How to make this php opencart 2.0 compatible? How to implement SQL CASE for calculation purpose -
i found code on opencart forum qphoria. seems 1.x.x know right way opencart 2.0?
function recalculateprice() { $response =& $this->locator->get('response'); $database =& $this->locator->get('database'); $url =& $this->locator->get('url'); $products= $database->getrows("select product_id, price product"); foreach ($products $product) { $sql = "update product set price = '?' product_id='?'"; $database->query($database->parse($sql,($product['price'] - $product['price'] * 0.02)), $product['product_id'])); } $response->redirect($url->ssl('product')); }
what want calculate query. thought in part.
example fields:
$product['wholesale'] $product['cost 1'] $product['cost 2'] $product['cost 3'] $product['cost 4'] $product['minimum_profit'] (cash) $product['margin'] $database->query($database->parse($sql, ($product['wholesale'] +$product['cost 1'] + $product['cost 2'] + $product['cost 3'] + $product['cost 4'] ) * (($product['margin'] / 100) + 1)) , $product['product_id']));
what need if / else
statement (($product['margin'] / 100) + 1))
if (($product['margin'] / 100) + 1)) < $product['minimum_profit'] $product['margin'] = $product['minimum_profit'] else $product['margin'] = (($product['margin'] / 100) + 1))
but how mysql? know how write ternary clueless how in mysql.
Comments
Post a Comment