The followings are the available columns in table 'product_related':
상속: extends CActiveRecord
 /**
  * Removes all related products
  *
  * @param string $passkey
  * @param int $intProductId
  * @return string
  */
 public function remove_related_products($passkey, $intProductId)
 {
     if (!$this->check_passkey($passkey)) {
         return self::FAIL_AUTH;
     }
     try {
         ProductRelated::model()->deleteAll('product_id= ' . $intProductId);
     } catch (Exception $e) {
         Yii::log("SOAP ERROR " . $e, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         return self::UNKNOWN_ERROR;
     }
     return self::OK;
 }
예제 #2
0
 protected function getSliderCriteria($autoadd = 0)
 {
     $criteria = new CDbCriteria();
     $criteria->distinct = true;
     $criteria->alias = 'Product';
     $criteria->join = 'LEFT JOIN ' . ProductRelated::model()->tableName() . ' as ProductRelated ON ProductRelated.related_id=Product.id';
     if (_xls_get_conf('INVENTORY_OUT_ALLOW_ADD', 0) == Product::InventoryMakeDisappear) {
         $criteria->condition = 'ProductRelated.product_id=:id AND inventory_avail>0 AND web=1 AND autoadd=' . $autoadd . ' AND parent IS NULL';
     } else {
         $criteria->condition = 'ProductRelated.product_id=:id AND web=1 AND autoadd=' . $autoadd . ' AND parent IS NULL';
     }
     $criteria->params = array(':id' => $this->id);
     $criteria->limit = _xls_get_conf('MAX_PRODUCTS_IN_SLIDER', 64);
     $criteria->order = 'Product.id DESC';
     return $criteria;
 }
예제 #3
0
 public function clearAllRelatedProductsRelations()
 {
     ProductRelated::model()->deleteAllByAttributes(array('product_id' => $this->product_id));
 }
예제 #4
0
 /**
  * Load a Related record with a given product and related product id. Used only by Soap uploader since we
  * have normal ORM relations.
  * @param $intProductId
  * @param $intRelatedId
  * @return CActiveRecord
  */
 public static function LoadByProductIdRelatedId($intProductId, $intRelatedId)
 {
     return ProductRelated::model()->findByAttributes(array('product_id' => $intProductId, 'related_id' => $intRelatedId));
 }
예제 #5
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();
         }
     }
 }
 /**
  * Product lookup and optional delete, shows inventory numbers
  */
 public function actionProducts()
 {
     if (isset($_POST['pk']) && isset($_POST['name']) && isset($_POST['value'])) {
         if ($_POST['name'] == 'code' && $_POST['value'] == "") {
             $items = CartItem::model()->findAll("product_id=" . $_POST['pk'] . " AND (cart_type=" . CartType::order . " OR cart_type=" . CartType::awaitpayment . ")");
             if ($items) {
                 echo "You cannot delete a product that has been used on an order";
             } else {
                 _dbx("set foreign_key_checks=0;");
                 Product::model()->updateAll(array('image_id' => null), 'id =' . $_POST['pk']);
                 Images::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductCategoryAssn::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductRelated::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductRelated::model()->deleteAllByAttributes(array('related_id' => $_POST['pk']));
                 ProductTags::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductQtyPricing::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductText::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 WishlistItem::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 TaskQueue::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 Product::model()->deleteByPk($_POST['pk']);
                 _dbx("set foreign_key_checks=1;");
                 echo "delete";
             }
         } else {
             echo Yii::t('admin', 'You cannot change a product code here. Delete the code to remove it manually from the Web Store database');
         }
     } else {
         $model = new Product();
         if (isset($_GET['q'])) {
             $model->code = $_GET['q'];
         }
         $this->render("products", array('model' => $model));
     }
 }
예제 #7
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;
 }