/** * main action */ public function mainAction() { require_once 'models/ecommerce/ecommerce_price.php'; $Price = new ecommerce_price(); /** * find selected currency code */ /* if (isset($_POST['client']['customer']['currency_code'])) { $currency_code = $_POST['client']['customer']['currency_code']; } else if (isset($_SESSION['client']['customer']['currency_code'])) { $currency_code = $_SESSION['client']['customer']['currency_code']; } else { $currency_code = $Price->conf['default_currency']; }*/ $currency_code = GLOBAL_LOCALE_CURRENCY; /** * get latest price for selected currency code */ $price_common = $Price->getLastPriceForVariety($this->GET['product_variety_id'], $currency_code, 'common'); $pt = array(); $pt['common'] = $price_common; $pt['discount'] = array(); /** * Display */ $this->tpl->assign("PRICE", $pt); if ($pt['discount']['value'] > 0) { $this->tpl->parse('content.price_discount'); } else { $this->tpl->parse('content.price_common'); } return true; }
/** * main action */ public function mainAction() { /** * TODO: * implement general updateSingleAttribute() */ //print_r($_POST); $model = $this->GET['model']; $attribute = $this->GET['attribute']; $update_value = trim($_POST['update_value']); $original_value = trim($_POST['original_html']); // currently implemented for product_variety.name and price.value switch ($model) { case 'common_node': require_once 'models/common/common_node.php'; $element_id_parts = explode('-', $_POST['element_id']); $variety_id = $element_id_parts[3]; $ModelObj = new common_node(); if (!$ModelObj->updateSingleAttribute($attribute, $update_value, $variety_id)) { msg('Failed', 'error'); } break; case 'ecommerce_product_variety': require_once 'models/ecommerce/ecommerce_product_variety.php'; $element_id_parts = explode('-', $_POST['element_id']); $variety_id = $element_id_parts[3]; $ModelObj = new ecommerce_product_variety(); if (!$ModelObj->updateSingleAttribute($attribute, $update_value, $variety_id)) { msg('Failed', 'error'); } break; case 'ecommerce_price': require_once 'models/ecommerce/ecommerce_price.php'; $ModelObj = new ecommerce_price(); $element_id_parts = explode('-', $_POST['element_id']); $variety_id = $element_id_parts[3]; $last_price = $ModelObj->getLastPriceForVariety($variety_id); //remove anything else than number and decimal point $update_value = preg_replace("/[^0-9\\.]*/", '', $update_value); //update only when the new price is different than old price if (round($last_price['value'], 2) != round($update_value, 2)) { if (!$ModelObj->updateSingleAttribute('value', $update_value, $last_price['id'])) { msg('Failed', 'error'); } } break; case 'international_translation': require_once 'models/international/international_translation.php'; $element_id_parts = explode('-', $_POST['element_id']); $updated_id = $element_id_parts[3]; $ModelObj = new international_translation(); if (!$ModelObj->updateSingleAttribute($attribute, $update_value, $updated_id)) { msg('Failed', 'error'); } break; default: return false; break; } if ($update_value != $original_value) { $value = $update_value; } else { $value = $original_value; } $this->tpl->assign('VALUE', $value); return true; }