/**
  * Add a related product
  *
  * @param string $passkey
  * @param int $intProductId
  * @param int $intRelatedId
  * @param int $intAutoadd
  * @param float $fltQty
  * @return string
  */
 public function add_related_product($passkey, $intProductId, $intRelatedId, $intAutoadd, $fltQty)
 {
     if (!$this->check_passkey($passkey)) {
         return self::FAIL_AUTH;
     }
     Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=0;')->execute();
     $related = ProductRelated::LoadByProductIdRelatedId($intProductId, $intRelatedId);
     $objProduct = Product::model()->findByPk($intProductId);
     $new = false;
     if (!$related instanceof ProductRelated) {
         $related = new ProductRelated();
     }
     //You can't auto add a master product
     if ($objProduct->master_model == 1) {
         $intAutoadd = 0;
     }
     $related->product_id = $intProductId;
     $related->related_id = $intRelatedId;
     $related->autoadd = $intAutoadd;
     $related->qty = $fltQty;
     if (!$related->save()) {
         Yii::log("SOAP ERROR : Error saving related {$intProductId} " . print_r($related->getErrors()), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         return self::UNKNOWN_ERROR . " Error saving category {$intProductId} " . print_r($related->getErrors(), true);
     }
     Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=1;')->execute();
     return self::OK;
 }
예제 #2
0
 protected function productSave($model)
 {
     $id = $model->id;
     if (!empty($model->categories)) {
         foreach ($model->categories as $catid) {
             $productCategories = new ProductCategory();
             $productCategories->product_id = $id;
             $productCategories->category_id = $catid;
             $productCategories->save();
         }
     }
     if (!empty($model->relatedA)) {
         foreach ($model->relatedA as $rid) {
             $productRelations = new ProductRelated();
             $productRelations->product_id = $id;
             $productRelations->related_id = $rid;
             $productRelations->save();
         }
     }
     if (!empty($model->stores)) {
         foreach ($model->stores as $sid) {
             $productStores = new ProductStore();
             $productStores->product_id = $id;
             $productStores->store_id = $sid;
             $productStores->save();
         }
     }
     $productImages = Yii::app()->user->getState('product_images');
     if (!empty($productImages)) {
         $this->addImages($id, 'ProductImage', 'product_images', 'Product');
     }
     if (!empty($this->_productoption)) {
         foreach ($this->_productoption as $productoption) {
             $optionModel = $productoption[0];
             $valueModel = $productoption[1];
             $optionModel->product_id = $id;
             $optionModel->save();
             foreach ($valueModel as $value) {
                 $value->product_option_id = $optionModel->id;
                 $value->product_id = $id;
                 $value->option_id = $optionModel->option_id;
                 $value->save();
             }
         }
     }
     if (!empty($this->_productattribute)) {
         foreach ($this->_productattribute as $productattribute) {
             $productattribute->product_id = $id;
             $productattribute->save();
         }
     }
     if (!empty($this->_productdiscount)) {
         foreach ($this->_productdiscount as $productdiscount) {
             $productdiscount->product_id = $id;
             $productdiscount->date_start = date('Y-m-d', strtotime($productdiscount->date_start));
             $productdiscount->date_end = date('Y-m-d', strtotime($productdiscount->date_end));
             $productdiscount->save();
         }
     }
     if (!empty($this->_productspecial)) {
         foreach ($this->_productspecial as $productspecial) {
             $productspecial->product_id = $id;
             $productspecial->date_start = date('Y-m-d', strtotime($productspecial->date_start));
             $productspecial->date_end = date('Y-m-d', strtotime($productspecial->date_end));
             $productspecial->save();
         }
     }
 }
예제 #3
0
 public function addRelatedProduct($relatedId)
 {
     if (!ProductRelated::model()->countByAttributes(array('product_id' => $this->product_id, 'related_id' => $relatedId))) {
         $productRelated = new ProductRelated();
         $productRelated->product_id = $this->product_id;
         $productRelated->related_id = $relatedId;
         return $productRelated->save();
     }
     return false;
 }
예제 #4
0
 /**
  * Add a related product
  *
  * @param string $passkey
  * @param int $intProductId
  * @param int $intRelatedId
  * @param int $intAutoadd
  * @param float $fltQty
  * @return string
  * @throws SoapFault
  *
  * @soap
  */
 public function add_related_product($passkey, $intProductId, $intRelatedId, $intAutoadd, $fltQty)
 {
     self::check_passkey($passkey);
     Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=0;')->execute();
     $related = ProductRelated::LoadByProductIdRelatedId($intProductId, $intRelatedId);
     $objProduct = Product::model()->findByPk($intProductId);
     $new = false;
     if (!$related instanceof ProductRelated) {
         $related = new ProductRelated();
     }
     //You can't auto add a master product
     if ($objProduct->master_model == 1) {
         $intAutoadd = 0;
     }
     $related->product_id = $intProductId;
     $related->related_id = $intRelatedId;
     $related->autoadd = $intAutoadd;
     $related->qty = $fltQty;
     if (!$related->save()) {
         $strMsg = "Error saving related {$intProductId}";
         Yii::log("SOAP ERROR : {$strMsg} " . print_r($related->getErrors()), CLogger::LEVEL_ERROR, 'application.' . __CLASS__ . "." . __FUNCTION__);
         throw new SoapFault($strMsg, WsSoapException::ERROR_UNKNOWN);
     }
     Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=1;')->execute();
     return self::OK;
 }