Esempio n. 1
0
 public static function SetFeaturedByKeyword($strKeyword)
 {
     Product::model()->updateAll(array('featured' => 0));
     Yii::app()->db->createCommand('update ' . Product::model()->tableName() . ' as a left join ' . ProductTags::model()->tableName() . ' as b on a.id=b.product_id left join ' . Tags::model()->tableName() . ' as c on b.tag_id=c.id set featured=1 where tag=:tag')->bindValue(':tag', $strKeyword)->execute();
 }
Esempio n. 2
0
 public static function DeleteProductTags($intProductId)
 {
     ProductTags::model()->deleteAll("product_id = " . $intProductId);
 }
Esempio n. 3
0
 /**
  * Creates the default product criteria that a custom page can use.
  *
  * @return CDbCriteria
  */
 public function getDefaultProductCriteria()
 {
     if (empty($this->product_tag)) {
         $this->product_tag = "";
     }
     $criteria = new CDbCriteria();
     $criteria->distinct = true;
     $criteria->alias = 'Product';
     $criteria->join = 'LEFT JOIN ' . ProductTags::model()->tableName() . ' as ProductTags ON ProductTags.product_id=Product.id LEFT JOIN ' . Tags::model()->tableName() . ' as Tags ON ProductTags.tag_id=Tags.id';
     if (_xls_get_conf('INVENTORY_OUT_ALLOW_ADD', 0) == Product::InventoryMakeDisappear) {
         $criteria->condition = 'inventory_avail > 0 AND web = 1 AND Tags.tag = :tag AND parent IS NULL';
     } else {
         $criteria->condition = 'web = 1 AND Tags.tag = :tag AND parent IS NULL';
     }
     $criteria->params = array(':tag' => $this->product_tag);
     return $criteria;
 }
 public function IsProductAffected($objItem)
 {
     $arrCode = unserialize(strtolower(serialize($this->LsCodeArray)));
     if (empty($arrCode)) {
         //no product restrictions
         return true;
     }
     $boolReturn = false;
     foreach ($arrCode as $strCode) {
         $strCode = strtolower($strCode);
         if (isset($objItem->product->family) && substr($strCode, 0, 7) == "family:" && trim(substr($strCode, 7, 255)) == strtolower($objItem->product->family->family)) {
             $boolReturn = true;
         }
         if (isset($objItem->product->class) && substr($strCode, 0, 6) == "class:" && trim(substr($strCode, 6, 255)) == strtolower($objItem->product->class->class_name)) {
             $boolReturn = true;
         }
         if (substr($strCode, 0, 8) == "keyword:") {
             $productTags = ProductTags::model()->findAllByAttributes(array('product_id' => $objItem->product->id));
             $strKeyword = trim(substr($strCode, 8, 255));
             foreach ($productTags as $tag) {
                 if (strtolower($tag->tag->tag) == $strKeyword) {
                     $boolReturn = true;
                 }
             }
         }
         if (substr($strCode, 0, 9) == "category:") {
             $arrTrail = Category::GetTrailByProductId($objItem->product->id, 'names');
             $strTrail = implode("|", $arrTrail);
             $strCompareCode = trim(substr($strCode, 9, 255));
             if ($strCompareCode == strtolower(substr($strTrail, 0, strlen($strCompareCode)))) {
                 $boolReturn = true;
             }
             $criteria = new CDbCriteria();
             $criteria->addCondition('product_id=' . $objItem->product->id);
             $hasMulticategory = Multicategory::model()->count($criteria);
             if ($hasMulticategory) {
                 $categoryOthers = Multicategory::model()->findAll();
                 foreach ($categoryOthers as $other) {
                     $otherCategory = Category::model()->findByPk($other->category_id);
                     if ($otherCategory && $otherCategory->label != "") {
                         if ($strCompareCode == strtolower($otherCategory->label)) {
                             return true;
                         }
                         if ($otherCategory->getParent()) {
                             if ($strCompareCode == strtolower($otherCategory->getParent()->label)) {
                                 return true;
                             }
                             if ($otherCategory->getParent()->getParent()) {
                                 if ($strCompareCode == strtolower($otherCategory->getParent()->getParent()->label)) {
                                     return true;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (_xls_array_search_restrict_begin(strtolower($objItem->code), $arrCode)) {
         $boolReturn = true;
     }
     //We normally return true if it's a match. If this code uses Except, then the logic is reversed
     if ($this->IsExcept()) {
         $boolReturn = $boolReturn == true ? false : true;
     }
     return $boolReturn;
 }
 /**
  * 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));
     }
 }