model() 공개 정적인 메소드

Returns the static model of the specified AR class.
public static model ( string $className = __CLASS__ ) : ProductRelated
$className string active record class name.
리턴 ProductRelated the static model class
 /**
  * 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 productUpdate($model)
 {
     $id = $model->id;
     ProductCategory::model()->deleteAll('product_id=:product_id', array(':product_id' => $id));
     if (!empty($model->categories)) {
         foreach ($model->categories as $catid) {
             $productCategories = new ProductCategory();
             $productCategories->product_id = $model->id;
             $productCategories->category_id = $catid;
             $productCategories->save();
         }
     }
     ProductRelated::model()->deleteAll('product_id=:product_id', array(':product_id' => $id));
     if (!empty($model->relatedA)) {
         foreach ($model->relatedA as $rid) {
             $productRelations = new ProductRelated();
             $productRelations->product_id = $id;
             $productRelations->related_id = $rid;
             $productRelations->save();
         }
     }
     ProductStore::model()->deleteAll('product_id=:product_id', array(':product_id' => $id));
     if (!empty($model->stores)) {
         foreach ($model->stores as $sid) {
             $productStores = new ProductStore();
             $productStores->product_id = $id;
             $productStores->store_id = $sid;
             $productStores->save();
         }
     }
     $this->deleteImages($model);
     $productImages = Yii::app()->user->getState('product_images');
     if (!empty($productImages)) {
         $this->addImages($model->id, 'ProductImage', 'product_images', 'Product');
     }
     //This needs to be updated, you cant delete
     ProductOption::model()->deleteAll('product_id=:product_id', array(':product_id' => $id));
     ProductOptionValue::model()->deleteAll('product_id=:product_id', array(':product_id' => $id));
     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();
         }
     }
     ProductAttribute::model()->deleteAll('product_id=:product_id', array(':product_id' => $id));
     if (!empty($this->_productattribute)) {
         foreach ($this->_productattribute as $productattribute) {
             $productattribute->product_id = $id;
             $productattribute->save();
         }
     }
     ProductDiscount::model()->deleteAll('product_id=:product_id', array(':product_id' => $id));
     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();
         }
     }
     ProductSpecial::model()->deleteAll('product_id=:product_id', array(':product_id' => $id));
     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
 /**
  * Removes all related products
  *
  * @param string $passkey
  * @param int $intProductId
  * @return string
  * @throws SoapFault
  * @soap
  */
 public function remove_related_products($passkey, $intProductId)
 {
     self::check_passkey($passkey);
     try {
         ProductRelated::model()->deleteAll('product_id= ' . $intProductId);
     } catch (Exception $e) {
         Yii::log("SOAP ERROR " . $e, CLogger::LEVEL_ERROR, 'application.' . __CLASS__ . "." . __FUNCTION__);
         throw new SoapFault("Unknown error", WsSoapException::ERROR_UNKNOWN);
     }
     return self::OK;
 }