Masteries Posted September 21, 2018 Share Posted September 21, 2018 (edited) Hey, Our shop has always used "Amount" for discounts instead of "Percentage" until now. However, we'd now like to switch to using percentage but doing it manually will be a pain in the ass because we got a lot of products. So, I just wanted to convert existing discounts that shows in amount to percentage and I accomplished this on product-list.tpl by using following formula & code: {if $product.specific_prices.reduction_type == 'amount'} -{((($product.price_without_reduction-$product.price)*100)/$product.price_without_reduction)|round:0}% {/if} However, adding the same code on product.tpl is generating the following PHP error: Fatal error: Cannot use object of type Product as array in ....../product.tpl I've tried troubleshooting it for a while now and I'm stuck. Any ideas? Edited September 21, 2018 by Masteries (see edit history) Link to comment Share on other sites More sharing options...
razaro Posted September 22, 2018 Share Posted September 22, 2018 Well error message is quite clear, you are trying to use object ( $product-> ) Product as array ( $product. ) so try {if $product->specific_prices.reduction_type == 'amount'} -{((($product->price_without_reduction-$product->price)*100)/$product->price_without_reduction)|round:0}% {/if} Link to comment Share on other sites More sharing options...
Masteries Posted September 22, 2018 Author Share Posted September 22, 2018 5 minutes ago, razaro said: Well error message is quite clear, you are trying to use object ( $product-> ) Product as array ( $product. ) so try {if $product->specific_prices.reduction_type == 'amount'} -{((($product->price_without_reduction-$product->price)*100)/$product->price_without_reduction)|round:0}% {/if} I already tried this but it gave me the following error: "Undefined property: Product::$price_without_reduction in ......" Link to comment Share on other sites More sharing options...
tuk66 Posted September 27, 2018 Share Posted September 27, 2018 There is probably no $product->price_without_reduction property in product.tpl. See getProductProperties() in Product.php. Link to comment Share on other sites More sharing options...
Masteries Posted September 27, 2018 Author Share Posted September 27, 2018 6 hours ago, tuk66 said: There is probably no $product->price_without_reduction property in product.tpl. See getProductProperties() in Product.php. There is one apparently: if (self::$_taxCalculationMethod == PS_TAX_EXC) { $row['price_tax_exc'] = Tools::ps_round($row['price_tax_exc'], 2); $row['price'] = Product::getPriceStatic( (int)$row['id_product'], true, $id_product_attribute, 6 ); $row['price_without_reduction'] = Product::getPriceStatic( (int)$row['id_product'], false, $id_product_attribute, 2, null, false, false ); } else { $row['price'] = Tools::ps_round( Product::getPriceStatic( (int)$row['id_product'], true, $id_product_attribute, 6 ), (int)Configuration::get('PS_PRICE_DISPLAY_PRECISION') ); $row['price_without_reduction'] = Product::getPriceStatic( (int)$row['id_product'], true, $id_product_attribute, 6, null, false, false ); } Link to comment Share on other sites More sharing options...
Masteries Posted September 29, 2018 Author Share Posted September 29, 2018 Anyone have a solution for this? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now