/** * main action */ public function mainAction() { $product_data = $_POST['product']; if (!isset($product_data['variety']['product_id'])) { $product_data['variety']['product_id'] = $product_data['id']; } require_once 'models/ecommerce/ecommerce_product_variety.php'; $Product_variety = new ecommerce_product_variety(); $this->tpl->assign("VARIETY_CONF", $Product_variety->conf); if ($_POST['save']) { if ($id = $Product_variety->insertFullVariety($product_data['variety'])) { msg("Product variety id={$id} has been added."); //empty $product_data = array(); } else { msg("Can't add the product variety for product id={$product_data['variety']['product_id']}. Is your product SKU unique? Did you fill in stock value?"); } } $this->tpl->assign('PRODUCT', $product_data); return true; }
/** * insert full product */ public function insertFullProduct($data) { /** * check input values */ if (trim($data['name']) == "") { msg('Product name is empty', 'error'); return false; } if (trim($data['variety']['name']) == "") { msg('Variety name is empty', 'error'); return false; } if (trim($data['variety']['sku']) == "") { msg('Variety SKU is empty', 'error'); return false; } if (!is_numeric($data['variety']['weight_gross'])) { msg('weight_gross is not numeric', 'error'); return false; } if (!is_numeric($data['variety']['stock'])) { msg('Stock value is not numeric', 'error'); return false; } if (trim($data['variety']['price']['currency_code']) == "") { msg('Currency code is empty', 'error'); return false; } if (trim($data['variety']['price']['type']) == "") { msg('Price type', 'error'); return false; } if (!is_numeric($data['variety']['price']['value'])) { msg('Price value is not numeric', 'error'); return false; } /** * prepare core product data */ $product_data = array(); $product_data['name'] = $data['name']; /** * insert */ if ($product_id = $this->insertProduct($product_data)) { require_once 'models/ecommerce/ecommerce_product_variety.php'; $Product_variety = new ecommerce_product_variety(); $data['variety']['product_id'] = $product_id; if ($product_variety_id = $Product_variety->insertFullVariety($data['variety'])) { //return product id, not product variety id return $product_id; } else { return false; } } else { return false; } }