Jump to content

Εμφάνιση έκπτωσης σε percentage % και όχι σε amount €


Prestan0ob

Recommended Posts

Σε 1.7 έχω δηλώσει ποσό έκτπωσης και όχι ποσοστό.
1780623106_.png.4c1285ad49b090fc1646df464cc6c8d4.png

Μπροστά όμως στο ποϊόν θέλω να δείχνω αντί για το ποσό έκπτωσης το αντίστοιχο ποσοστό.

Οι γραμμές κώδικα που δείχνουν αντίστοιχα ποσοστό ή ποσό έκπτωσης ανάλογα με το τι έχεις βάλει στο admin είναι αυτές:

 <!-- {if $product.discount_type === 'percentage'}
                  <span class="discount-percentage discount-product">{$product.discount_percentage}</span>
                {elseif $product.discount_type === 'amount'}
                  <span class="discount-amount discount-product">{$product.discount_amount_to_display}</span>
                {/if} -->

Καμιά ιδέα πως μπορώ να υπολογίζω το ποσοστό έκπτωσης απο το ποσό έκπτωσης και να το δείχνω στην περίπτωση πιο πάνω "product.discount_type === 'amount'" ?

εικόνα.png

Link to comment
Share on other sites

Τώρα κατάλαβα.

Στο round βάζεις τα δεκαδικά που θέλεις.

{if $product.discount_type === 'percentage'}
  <span class="discount-percentage discount-product">{$product.discount_percentage}</span>
{elseif $product.discount_type === 'amount'}
  <span class="discount-amount discount-product">{((($product.price_without_reduction - $product.price_with_reduction)*100)/$product.price_without_reduction)|round:0}</span>
{/if}

Source:

 

Link to comment
Share on other sites

Τελικά ο κώδικας είναι σε άλλο σημείο και είναι ο παρακάτω.

Προσπάθησα να προσαρμόσω στο συγκεκριμένο σημείο αλλά δεν τα κατάφερα. Φέρνει κενό.

 

 {if $product.discount_type === 'percentage'}
              <span class="discount discount-percentage">{l s='Save %percentage%' d='Shop.Theme.Catalog' sprintf=['%percentage%' => $product.discount_percentage_absolute]}</span>
            {else}
              <span class="discount discount-amount">{l s='Save %amount%' d='Shop.Theme.Catalog' sprintf=['%amount%' => $product.discount_amount]}</span>
            {/if}

 

Link to comment
Share on other sites

Quote

         {if $product.discount_type === 'percentage'}
              <span class="discount discount-percentage">{l s='Save %percentage%' d='Shop.Theme.Catalog' sprintf=['%percentage%' => $product.discount_percentage_absolute]}</span>
            {else}

              <span class="discount discount-amount">{round((1-$product.price/$product.regular_price)*100,0)} %</span>
                        
            {/if}

Και εμφανίζει αυτό
345049546_.png.b4371f262c850b332d945ca4e3e8bd5b.png

Το έφτιαξα με βοήθεια αυτό που ανέβασες και είναι πιο πάνω για όποιον ενδιαφέρετε. Ευχαριστώ.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...