Search code examples
phpformulaopencartpercentageopencart-3

Decrease percentage of the price variable - OpenCart


I am interested in one aspect, I want to show price on OpenCart product page with -11.76470588% from final price. Or: I need to display two type of prices.

So is there a way? Variable: {{ price }} Or something like this: 1 - ({{ price }} / 1.19 * 1.05) / X

Thank you!

My code:

    {% if category_id=='69' %}
                    
                        <div class="pret-cu-tva5">Preț cu TVA 5&#37;:   {% if price %}
                {#========= Product - Price ========= #}
                <div class="product_page_price price" itemprop="offerDetails" itemscope itemtype="http://data-vocabulary.org/Offer">
                    {% if not special %}
                        <span class="price-new"><span itemprop="price" id="price-old">{{ price }}</span></span>
                    {% else %}
                        <span class="price-new"><span itemprop="price" id="price-special">{{ special }}</span></span>
                       <span class="price-old" id="price-old">{{ price }}</span>
                    {% endif %}
                    
                    {% if special and soconfig.get_settings('listing_discount_status')   %} 
                    {#=======Discount Label======= #}
                    <span class="label-product label-sale">
                         {{ discount }}
                    </span>
                    {% endif %} 

                    {% if tax %}
                        <div class="price-tax"><span>{{ text_tax }}</span> <span id="price-tax"> {{ tax }} </span></div>
                    {% endif %}
                 
                </div>
                
                
            
                
                
                {% endif %}
                    

                {% if discounts %} 
                    <ul class="list-unstyled text-success">
                    {% for discount in discounts %} 
                        <li><strong>{{ discount.quantity }} {{ text_discount }} {{ discount.price }}</strong> </li>
                    {% endfor %}
                    </ul>
                {% endif %}  </div>

No results, tried $percent = (($rowx->Orgprice - $rowx->SalePrice)*100) /$rowx->Orgprice ;


Solution

  • In the PHP template that Opencart uses, {{ price }} is the expression. Everything must be within the {{ }} for the calculation. So, apply the adjustments as such:

    {{ price * .88235 }} or {{ 1 - (price/ 1.19 * 1.05) }}/X

    in your very specific case.