Psytanium Posted March 7, 2018 Share Posted March 7, 2018 Hello, I have modified the calculate_price function in class/currencies.php to add a discount in some countries, it is working fine, but I want to exclude the discount if the product already have already a special price. How can I add "if product is special" to this function ? function calculate_price( $products_price, $products_tax, $quantity = 1) { global $currency, $country, $country_vat_disc; if (!in_array($country, $country_vat_disc)) { $discount = tep_add_tax( $products_price, $products_tax ) * 0.1; } return tep_round( tep_add_tax( $products_price, $products_tax ) - $discount, $this->currencies[ $currency ][ 'decimal_places' ] ) * $quantity; } I tried this function calculate_price( $products_price, $products_tax, $quantity = 1) { global $currency, $country, $country_vat_disc, $product_id; if( tep_get_products_special_price( $product_id ) !== null ) { $ifspecial = true; } if (!in_array($country, $country_vat_disc) && !$ifspecial) { $discount = tep_add_tax( $products_price, $products_tax ) * 0.1; } else { $discount = 0; } return tep_round( tep_add_tax( $products_price, $products_tax ) - $discount, $this->currencies[ $currency ][ 'decimal_places' ] ) * $quantity; } but didn't work. Thank you for any suggestion :) Link to comment Share on other sites More sharing options...
MrPhil Posted March 7, 2018 Share Posted March 7, 2018 Have you confirmed that tep_get_products_special_price() returns a null and not a 0 or other unexpected result if the product does not have a special price? I'm always a bit leery of code that doesn't explicitly return a null, but relies on something of a side-effect of something not being set (possibly NULL default) in the database. See if == null or != null might be needed, rather than !== or === comparisons. When you say "it didn't work", that means that $ifspecial is never being set true, even when it should be? You might want to check if you need a different comparison for setting $ifspecial. That would be my best guess for where the problem is. Link to comment Share on other sites More sharing options...
Psytanium Posted March 8, 2018 Author Share Posted March 8, 2018 @MrPhil Thank you for your support on almost all topics :) I tried if ( !empty(tep_get_products_special_price( $product_id )) ... I think the variable $product_id is not passed to the function. tep_get_products_special_price( $product_id ) I don't know if there is a ready to use function, to test if a product is special. Link to comment Share on other sites More sharing options...
Psytanium Posted March 8, 2018 Author Share Posted March 8, 2018 in product_info.php i added $product_id = $product_info[ 'products_id' ]; now the function is working. But this solution require adding $product_id in every page of the website, product_listing.php, shopping_cart, checkout pages, etc... I don't know if there is easier solution, to test specials, without modifying every page. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.