/** * Get Category attached to product * @return string|array */ public function getCategory() { $arrTrailFull = Category::GetTrailByProductId($this->id); $objCat = Category::model()->findbyPk($arrTrailFull[0]['key']); return $objCat; }
function _xls_get_googleparentcategory($intProductRowid) { $arrTrailFull = Category::GetTrailByProductId($intProductRowid); $objCat = Category::model()->findbyPk($arrTrailFull[0]['key']); $objPar = $objCat->integration->google; if ($objPar) { $strLine = $objPar->name0; $strMeta = $objPar->extra; } else { $strLine = ""; } $strLine = str_replace("&", "&", $strLine); $strLine = str_replace(">", ">", $strLine); $arrGoogle = array(); $arrGoogle['Category'] = trim($strLine); if (!empty($strMeta)) { $arrX = explode(",", $strMeta); $arrGoogle['Gender'] = $arrX[0]; $arrGoogle['Age'] = $arrX[1]; } return $arrGoogle; }
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; }
public function run() { // place the action logic here //Load some information we'll use within the loops $intStockHandling = _xls_get_conf('INVENTORY_OUT_ALLOW_ADD', 0); $intGoogleMPN = _xls_get_conf('GOOGLE_MPN', 0); $strQueryAddl = $intStockHandling == 0 ? " AND inventory_avail>0" : ""; header("content-type: text/xml;charset=UTF-8"); echo '<?xml version="1.0" encoding="UTF-8"?>' . chr(13); echo ' <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">' . chr(13); echo '<channel>' . chr(13); echo ' <title><![CDATA[' . _xls_get_conf('STORE_NAME', 'Lightspeed Web Store') . ']]></title>' . chr(13); echo ' <link>' . _xls_site_url() . '</link>' . chr(13); echo ' <description><![CDATA[' . _xls_get_conf('STORE_TAGLINE') . ']]></description>' . chr(13); // We only want active web products that are not master products // https://support.google.com/merchants/answer/188494 $sql = 'SELECT * FROM ' . Product::model()->tableName() . ' WHERE current=1 AND web=1 AND master_model=0 ' . $strQueryAddl . ' ORDER BY id'; if (isset($_GET['group'])) { $intGroup = _xls_number_only($_GET['group']); if ($intGroup < 1) { $intGroup = 1; } $parse = _xls_get_conf('GOOGLE_PARSE', 5000); switch ($intGroup) { case 1: $sql .= " limit " . $parse; break; default: $sql .= " limit " . ($intGroup - 1) * $parse . "," . $parse; break; } } $arrProducts = Yii::app()->db->createCommand($sql)->query(); while (($arrItem = $arrProducts->read()) !== false) { $objProduct = Product::model()->findByPk($arrItem['id']); $arrGoogle = _xls_get_googlecategory($objProduct->id); $strGoogle = $arrGoogle['Category']; $arrTaxGrids = $objProduct->GetTaxRateGrid(); $arrTrail = Category::GetTrailByProductId($objProduct->id, 'names'); //If our current category doesn't have Google set but we have a parent that does, use it if (empty($strGoogle) && count($arrTrail) > 1) { $arrGoogle = _xls_get_googleparentcategory($objProduct->id); $strGoogle = $arrGoogle['Category']; } echo '<item>' . chr(13); echo chr(9) . "<g:id>" . $objProduct->id . "</g:id>" . chr(13); echo chr(9) . '<title><![CDATA[' . strip_tags($objProduct->Title) . ']]></title>' . chr(13); if ($objProduct->description_long) { echo chr(9) . '<description><![CDATA[' . $objProduct->WebLongDescription . ']]></description>' . chr(13); } if ($strGoogle) { echo chr(9) . '<g:google_product_category>' . $strGoogle . '</g:google_product_category>' . chr(13); } if ($arrTrail) { echo chr(9) . '<g:product_type><![CDATA[' . implode(" > ", $arrTrail) . ']]></g:product_type>' . chr(13); } echo chr(9) . '<link>' . $objProduct->directUrl . '</link>' . chr(13); if ($objProduct->image_id) { $arrProductImages = $objProduct->getProductPhotos(true); if ($arrProductImages) { echo chr(9) . '<g:image_link>' . $arrProductImages[0]['image'] . '</g:image_link>' . chr(13); for ($index = 1; $index < count($arrProductImages); $index++) { echo chr(9) . '<g:additional_image_link>' . $arrProductImages[$index]['image'] . '</g:additional_image_link>' . chr(13); } } } echo chr(9) . '<g:condition>new</g:condition>' . chr(13); if ($objProduct->IsAddable) { echo chr(9) . '<g:availability>in stock</g:availability>' . chr(13); } else { echo chr(9) . '<g:availability>out of stock</g:availability>' . chr(13); } echo chr(9) . '<g:price>' . $objProduct->PriceValue . '</g:price>' . chr(13); echo chr(9) . '<g:brand><![CDATA[' . $objProduct->Family . ']]></g:brand>' . chr(13); echo chr(9) . '<g:gtin>' . $objProduct->upc . '</g:gtin>' . chr(13); if ($intGoogleMPN) { echo chr(9) . '<g:mpn><![CDATA[' . $objProduct->code . ']]></g:mpn>' . chr(13); } if (substr($strGoogle, 0, 7) == "Apparel") { echo chr(9) . '<g:gender>' . $arrGoogle['Gender'] . '</g:gender>' . chr(13); echo chr(9) . '<g:age_group>' . $arrGoogle['Age'] . '</g:age_group>' . chr(13); } echo chr(9) . '<g:color><![CDATA[' . $objProduct->product_color . ']]></g:color>' . chr(13); echo chr(9) . '<g:size><![CDATA[' . $objProduct->product_size . ']]></g:size>' . chr(13); if ($objProduct->parent > 0) { echo chr(9) . '<item_group_id>' . $objProduct->parent . '</item_group_id>' . chr(13); } foreach ($arrTaxGrids as $arrTaxGrid) { echo chr(9) . '<g:tax>' . chr(13); echo chr(9) . ' <g:country>' . $arrTaxGrid[0] . '</g:country>' . chr(13); echo chr(9) . ' <g:region>' . $arrTaxGrid[1] . '</g:region>' . chr(13); echo chr(9) . ' <g:rate>' . $arrTaxGrid[2] . '</g:rate>' . chr(13); echo chr(9) . ' <g:tax_ship>' . $arrTaxGrid[3] . '</g:tax_ship>' . chr(13); echo chr(9) . '</g:tax> ' . chr(13); } echo chr(9) . '<g:shipping_weight>' . $objProduct->product_weight . '</g:shipping_weight>' . chr(13); echo '</item>' . chr(13); } echo '</channel>' . chr(13); echo '</rss>'; Yii::app()->db->createCommand("UPDATE xlsws_modules set active=1 where module='wsgooglemerchant'")->execute(); }