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(); }
/** * Save a product in the database (Create if need be) * * @param string $passkey * @param int $intRowid * @param string $strCode * @param string $strName * @param string $blbImage * @param string $strClassName * @param int $blnCurrent * @param string $strDescription * @param string $strDescriptionShort * @param string $strFamily * @param int $blnGiftCard * @param int $blnInventoried * @param double $fltInventory * @param double $fltInventoryTotal * @param int $blnMasterModel * @param int $intMasterId * @param string $strProductColor * @param string $strProductSize * @param double $fltProductHeight * @param double $fltProductLength * @param double $fltProductWidth * @param double $fltProductWeight * @param int $intTaxStatusId * @param double $fltSell * @param double $fltSellTaxInclusive * @param double $fltSellWeb * @param string $strUpc * @param int $blnOnWeb * @param string $strWebKeyword1 * @param string $strWebKeyword2 * @param string $strWebKeyword3 * @param int $blnFeatured * @param string $strCategoryPath * @return string */ public function save_product($passkey, $intRowid, $strCode, $strName, $blbImage, $strClassName, $blnCurrent, $strDescription, $strDescriptionShort, $strFamily, $blnGiftCard, $blnInventoried, $fltInventory, $fltInventoryTotal, $blnMasterModel, $intMasterId, $strProductColor, $strProductSize, $fltProductHeight, $fltProductLength, $fltProductWidth, $fltProductWeight, $intTaxStatusId, $fltSell, $fltSellTaxInclusive, $fltSellWeb, $strUpc, $blnOnWeb, $strWebKeyword1, $strWebKeyword2, $strWebKeyword3, $blnFeatured, $strCategoryPath) { if (!$this->check_passkey($passkey)) { return self::FAIL_AUTH; } // We must preservice the Rowid of Products within the Web Store // database and must therefore see if it already exists $objProduct = Product::model()->findByPk($intRowid); if (!$objProduct) { $objProduct = new Product(); $objProduct->id = $intRowid; } $strName = trim($strName); $strName = trim($strName, '-'); $strName = substr($strName, 0, 255); $strCode = trim($strCode); $strCode = str_replace('"', '', $strCode); $strCode = str_replace("'", '', $strCode); if (empty($strName)) { $strName = 'missing-name'; } if (empty($strDescription)) { $strDescription = ''; } $objProduct->code = $strCode; $objProduct->title = $strName; //$objProduct->class_name = $strClassName; $objProduct->current = $blnCurrent; $objProduct->description_long = $strDescription; $objProduct->description_short = $strDescriptionShort; //$objProduct->family = $strFamily; $objProduct->gift_card = $blnGiftCard; $objProduct->inventoried = $blnInventoried; $objProduct->inventory = $fltInventory; $objProduct->inventory_total = $fltInventoryTotal; $objProduct->master_model = $blnMasterModel; if ($intMasterId > 0) { $objProduct->parent = $intMasterId; } else { $objProduct->parent = null; } $objProduct->product_color = $strProductColor; $objProduct->product_size = $strProductSize; $objProduct->product_height = $fltProductHeight; $objProduct->product_length = $fltProductLength; $objProduct->product_width = $fltProductWidth; $objProduct->product_weight = $fltProductWeight; $objProduct->tax_status_id = $intTaxStatusId; $objProduct->sell = $fltSell; $objProduct->sell_tax_inclusive = $fltSellTaxInclusive; //If we're in TaxIn Mode, then SellWeb has tax and we reverse it. if (_xls_get_conf('TAX_INCLUSIVE_PRICING', 0) == 1) { if ($fltSellWeb != 0) { //Tax in with a sell on web price $objProduct->sell_web_tax_inclusive = $fltSellWeb; //LS sends tax in web already $objProduct->sell_web = Tax::StripTaxesFromPrice($fltSellWeb, $intTaxStatusId); } else { //We use our regular prices and copy them price $objProduct->sell_web_tax_inclusive = $fltSellTaxInclusive; $objProduct->sell_web = $fltSell; } } else { if ($fltSellWeb != 0) { $objProduct->sell_web = $fltSellWeb; } else { $objProduct->sell_web = $fltSell; } } $objProduct->upc = $strUpc; $objProduct->web = $blnOnWeb; $objProduct->featured = $blnFeatured; $fltReserved = $objProduct->CalculateReservedInventory(); $objProduct->inventory_reserved = $fltReserved; if (Yii::app()->params['INVENTORY_FIELD_TOTAL'] == 1) { $objProduct->inventory_avail = $fltInventoryTotal - $fltReserved; } else { $objProduct->inventory_avail = $fltInventory - $fltReserved; } //Because Lightspeed may send us products out of sequence (child before parent), we have to turn this off Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=0;')->execute(); if (!$objProduct->save()) { Yii::log("SOAP ERROR : Error saving product {$intRowid} {$strCode} " . print_r($objProduct->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); return self::UNKNOWN_ERROR . " Error saving product {$intRowid} {$strCode} " . print_r($objProduct->getErrors(), true); } $strFeatured = _xls_get_conf('FEATURED_KEYWORD', 'XnotsetX'); if (empty($strFeatured)) { $strFeatured = 'XnotsetX'; } //Save keywords $strTags = trim($strWebKeyword1) . "," . trim($strWebKeyword2) . "," . trim($strWebKeyword3); $strTags = str_replace(",,", ",", $strTags); $arrTags = explode(",", $strTags); ProductTags::DeleteProductTags($objProduct->id); foreach ($arrTags as $indivTag) { if (!empty($indivTag)) { $tag = Tags::model()->findByAttributes(array('tag' => $indivTag)); if (!$tag instanceof Tags) { $tag = new Tags(); $tag->tag = $indivTag; $tag->save(); } $objProductTag = new ProductTags(); $objProductTag->product_id = $objProduct->id; $objProductTag->tag_id = $tag->id; $objProductTag->save(); if ($strFeatured != 'XnotsetX' && $objProduct->web && $indivTag == $strFeatured) { $objProduct->featured = 1; $objProduct->save(); } } } if (!empty($strFamily)) { $objFamily = Family::model()->findByAttributes(array('family' => $strFamily)); if ($objFamily instanceof Family) { $objProduct->family_id = $objFamily->id; $objProduct->save(); } else { $objFamily = new Family(); $objFamily->family = $strFamily; $objFamily->child_count = 0; $objFamily->request_url = _xls_seo_url($strFamily); $objFamily->save(); $objProduct->family_id = $objFamily->id; $objProduct->save(); } $objFamily->UpdateChildCount(); } else { if ($objProduct->family_id) { $objFamily = Family::model()->findByAttributes(array('id' => $objProduct->family_id)); $objProduct->family_id = null; $objProduct->save(); $objFamily->UpdateChildCount(); } } if (!empty($strClassName)) { $objClass = Classes::model()->findByAttributes(array('class_name' => $strClassName)); if ($objClass instanceof Classes) { $objProduct->class_id = $objClass->id; $objProduct->save(); } else { $objClass = new Classes(); $objClass->class_name = $strClassName; $objClass->child_count = 0; $objClass->request_url = _xls_seo_url($strClassName); $objClass->save(); $objProduct->class_id = $objClass->id; $objProduct->save(); } $objClass->UpdateChildCount(); } // Save category $strCategoryPath = trim($strCategoryPath); if ($strCategoryPath && $strCategoryPath != "Default") { $arrCategories = explode("\t", $strCategoryPath); $intCategory = Category::GetIdByTrail($arrCategories); if (!is_null($intCategory)) { $objCategory = Category::model()->findByPk($intCategory); //Delete any prior categories from the table ProductCategoryAssn::model()->deleteAllByAttributes(array('product_id' => $objProduct->id)); $objAssn = new ProductCategoryAssn(); $objAssn->product_id = $objProduct->id; $objAssn->category_id = $intCategory; $objAssn->save(); $objCategory->UpdateChildCount(); } } else { ProductCategoryAssn::model()->deleteAllByAttributes(array('product_id' => $objProduct->id)); } Product::convertSEO($intRowid); //Build request_url Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=1;')->execute(); $objEvent = new CEventProduct('LegacysoapController', 'onSaveProduct', $objProduct); _xls_raise_events('CEventProduct', $objEvent); // return self::OK; }
public static function DeleteProductTags($intProductId) { ProductTags::model()->deleteAll("product_id = " . $intProductId); }
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; }
/** * 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; }
/** * 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)); } }