Exemplo n.º 1
0
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/ecommerce/ecommerce_price.php';
     $Price = new ecommerce_price();
     // type
     $types = $Price->getTypes();
     foreach ($types as $type) {
         $this->tpl->assign('TYPE', $type);
         if ($type == $_POST['price']['type'] || $type == $this->GET['type']) {
             $this->tpl->assign('SELECTED', "selected='selected'");
         } else {
             $this->tpl->assign('SELECTED', "");
         }
         $this->tpl->parse('content.type');
     }
     if ($_POST['save']) {
         $price_data = $_POST['price'];
         // FIXME: form_currency_inline hack
         $price_data['currency_code'] = $_POST['client']['customer']['currency_code'];
         if ($id = $Price->priceInsert($price_data)) {
             msg("Price added.");
             require_once 'models/ecommerce/ecommerce_product_variety.php';
             $Product_variety = new ecommerce_product_variety();
             $pd = $Product_variety->detail($price_data['product_variety_id']);
         } else {
             return false;
         }
     }
     $this->tpl->assign('PRICE', $_POST['price']);
     return true;
 }
 /**
  * insert full product
  */
 public function insertFullVariety($data)
 {
     /**
      * check input values
      */
     if (!is_numeric($data['product_id'])) {
         msg('product_id is not numeric', 'error');
         return false;
     }
     if (!is_numeric($data['product_type_id'])) {
         msg('Product type id is not numeric', 'error');
         return false;
     }
     if (trim($data['name']) == "") {
         msg('Variety name is empty', 'error');
         return false;
     }
     if (trim($data['sku']) == "") {
         msg('Variety SKU is empty', 'error');
         return false;
     }
     if (!is_numeric($data['weight_gross'])) {
         msg('weight_gross is not numeric', 'error');
         return false;
     }
     if (!is_numeric($data['stock'])) {
         msg('Stock value is not numeric', 'error');
         return false;
     }
     if (trim($data['price']['currency_code']) == "") {
         msg('Currency code is empty', 'error');
         return false;
     }
     if (trim($data['price']['type']) == "") {
         msg('Price type', 'error');
         return false;
     }
     if (!is_numeric($data['price']['value'])) {
         msg('Price value is not numeric', 'error');
         return false;
     }
     /**
      * set net weight same as gross if not provided
      */
     if (!is_numeric($data['weight'])) {
         $data['weight'] = $data['weight_gross'];
     }
     /**
      * prepare core variety data
      */
     $variety_data = array();
     $variety_data['product_id'] = $data['product_id'];
     $variety_data['name'] = $data['name'];
     $variety_data['sku'] = $data['sku'];
     $variety_data['weight_gross'] = $data['weight_gross'];
     $variety_data['weight'] = $data['weight'];
     $variety_data['stock'] = $data['stock'];
     $variety_data['product_type_id'] = $data['product_type_id'];
     /**
      * insert
      */
     if ($product_variety_id = $this->insertVariety($variety_data)) {
         require_once 'models/ecommerce/ecommerce_price.php';
         $Price = new ecommerce_price();
         $price_data = $data['price'];
         $price_data['product_variety_id'] = $product_variety_id;
         if ($price_id = $Price->priceInsert($price_data)) {
             return $product_variety_id;
         } else {
             msg("Adding of price failed", "error");
             //it's still quite positive result :)
             return true;
         }
     } else {
         msg("Can't add product variety. Are you sure SKU is not used by other product?", "error");
         return false;
     }
 }