/**
  * Get and assign attributes combinations informations
  */
 protected function assignAttributesCombinations()
 {
     $attributes_combinations = Product::getAttributesInformationsByProduct($this->product->id);
     foreach ($attributes_combinations as &$ac) {
         foreach ($ac as &$val) {
             $val = str_replace('-', '_', Tools::link_rewrite($val));
         }
     }
     $this->context->smarty->assign('attributesCombinations', $attributes_combinations);
 }
Example #2
0
 /**
  * Get and assign attributes combinations informations
  */
 protected function assignAttributesCombinations()
 {
     $attributes_combinations = Product::getAttributesInformationsByProduct($this->product->id);
     if (is_array($attributes_combinations) && count($attributes_combinations)) {
         foreach ($attributes_combinations as &$ac) {
             foreach ($ac as &$val) {
                 $val = str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite(str_replace(array(',', '.'), '-', $val)));
             }
         }
     } else {
         $attributes_combinations = array();
     }
     $this->context->smarty->assign(array('attributesCombinations' => $attributes_combinations, 'attribute_anchor_separator' => Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR')));
 }
 /**
  * Convert the entities data into an xml object and return the xml object as a string
  *
  * @param array $aEntity Entity data
  */
 public function formatEntityToXML($aEntity)
 {
     $sReturn = '';
     $dom = new DOMDocument('1.0', 'utf-8');
     $bUseRoutes = (bool) Configuration::get('PS_REWRITING_SETTINGS');
     $oDispatcher = Dispatcher::getInstance();
     // Force the dispatcher to use custom routes because the use of custom routes is disabled in the BO Context
     foreach ($oDispatcher->default_routes as $route_id => $route_data) {
         if ($custom_route = Configuration::get('PS_ROUTE_' . $route_id)) {
             foreach (Language::getLanguages() as $lang) {
                 $oDispatcher->addRoute($route_id, $custom_route, $route_data['controller'], $lang['id_lang'], $route_data['keywords'], isset($route_data['params']) ? $route_data['params'] : array());
             }
         }
     }
     $oPrediggoConfig = $this->aPrediggoConfigs[(int) $aEntity['id_shop']];
     $link = $oPrediggoConfig->getContext()->link;
     $oProduct = new Product((int) $aEntity['id_product'], true, null, (int) $aEntity['id_shop'], $oPrediggoConfig->getContext());
     if ((int) StockAvailable::getQuantityAvailableByProduct((int) $aEntity['id_product'], 0, (int) $aEntity['id_shop']) < (int) $oPrediggoConfig->export_product_min_quantity) {
         $this->nbEntitiesTreated--;
         $this->nbEntities--;
         return ' ';
     }
     $ps_tax = (int) Configuration::get('PS_TAX');
     foreach ($this->aLanguages as $aLanguage) {
         $id_lang = (int) $aLanguage['id_lang'];
         // Set the root of the XML
         $root = $dom->createElement($this->sEntity);
         $dom->appendChild($root);
         $root->setAttribute('timestamp', (int) strtotime($oProduct->date_add));
         $id = $dom->createElement('id', (int) $oProduct->id);
         $root->appendChild($id);
         $profile = $dom->createElement('profile', (int) $aEntity['id_shop']);
         $root->appendChild($profile);
         $name = $dom->createElement('name');
         $name->appendChild($dom->createCDATASection($oProduct->name[$id_lang]));
         $root->appendChild($name);
         $oCategory = new Category((int) $oProduct->id_category_default);
         $aCategories = $oCategory->getParentsCategories($id_lang);
         if (is_array($aCategories) && count($aCategories) > 0) {
             foreach ($aCategories as $aCategory) {
                 $oCategoryTmp = new Category((int) $aCategory['id_category'], $id_lang);
                 if (!empty($oCategoryTmp->name)) {
                     $genre = $dom->createElement('genre');
                     $genre->appendChild($dom->createCDATASection($oCategoryTmp->name));
                     $root->appendChild($genre);
                 }
                 unset($oCategoryTmp);
             }
         }
         unset($aCategories);
         unset($oCategory);
         if (!empty($oProduct->ean13)) {
             $ean = $dom->createElement('ean');
             $ean->appendChild($dom->createCDATASection($oProduct->ean13));
             $root->appendChild($ean);
         }
         $price = $dom->createElement('price', number_format($oProduct->getPrice($ps_tax), 2, '.', ''));
         $root->appendChild($price);
         if (isset($oProduct->tags[$id_lang]) && ($aTags = $oProduct->tags[$id_lang])) {
             $tag = $dom->createElement('tag');
             $tag->appendChild($dom->createCDATASection(join(',', $aTags)));
             $root->appendChild($tag);
         }
         $sDesc = trim(strip_tags($oProduct->description[$id_lang]));
         if ($oPrediggoConfig->export_product_description && !empty($sDesc)) {
             $description = $dom->createElement('description');
             $description->appendChild($dom->createCDATASection($sDesc));
             $root->appendChild($description);
         }
         if (!empty($oProduct->id_manufacturer)) {
             $supplierid = $dom->createElement('supplierid', (int) $oProduct->id_manufacturer);
             $root->appendChild($supplierid);
         }
         $recommendable = $dom->createElement('recommendable', in_array((int) $oProduct->id, explode(',', $oPrediggoConfig->products_ids_not_recommendable)) ? 'false' : 'true');
         $root->appendChild($recommendable);
         $searchable = $dom->createElement('searchable', in_array((int) $oProduct->id, explode(',', $oPrediggoConfig->products_ids_not_searchable)) ? 'false' : 'true');
         $root->appendChild($searchable);
         // Set product URL
         $attribute = $dom->createElement('attribute');
         $root->appendChild($attribute);
         $attName = $dom->createElement('attName', 'producturl');
         $attribute->appendChild($attName);
         $attValue = $dom->createElement('attValue');
         $attValue->appendChild($dom->createCDATASection($link->getProductLink((int) $oProduct->id, $oProduct->link_rewrite[$id_lang], Category::getLinkRewrite((int) $oProduct->id_category_default, $id_lang), NULL, $id_lang, (int) $aEntity['id_shop'], 0, $bUseRoutes)));
         $attribute->appendChild($attValue);
         // Set product picture
         if ($oPrediggoConfig->export_product_image) {
             $attribute = $dom->createElement('attribute');
             $root->appendChild($attribute);
             $attName = $dom->createElement('attName', 'imageurl');
             $attribute->appendChild($attName);
             $aCover = $oProduct->getCover((int) $oProduct->id);
             $attValue = $dom->createElement('attValue');
             $attValue->appendChild($dom->createCDATASection($link->getImageLink($oProduct->link_rewrite[$id_lang], (int) $aCover['id_image'], 'large')));
             $attribute->appendChild($attValue);
         }
         // Set combinations
         $aProductCombinations = Product::getAttributesInformationsByProduct((int) $oProduct->id);
         if (sizeof($aProductCombinations)) {
             foreach ($aProductCombinations as $aProductCombination) {
                 if (!empty($oPrediggoConfig->attributes_groups_ids) && in_array((int) $aProductCombination['id_attribute_group'], explode(',', $oPrediggoConfig->attributes_groups_ids))) {
                     $attribute = $dom->createElement('attribute');
                     $root->appendChild($attribute);
                     $attName = $dom->createElement('attName');
                     $attName->appendChild($dom->createCDATASection($aProductCombination['group']));
                     $attribute->appendChild($attName);
                     $attValue = $dom->createElement('attValue');
                     $attValue->appendChild($dom->createCDATASection($aProductCombination['attribute']));
                     $attribute->appendChild($attValue);
                 }
             }
         }
         unset($aProductCombinations);
         // Set features
         $aProductFeatures = $oProduct->getFrontFeatures($id_lang);
         if (sizeof($aProductFeatures)) {
             foreach ($aProductFeatures as $aProductFeature) {
                 if (!empty($oPrediggoConfig->features_ids) && in_array((int) $aProductFeature['id_feature'], explode(',', $oPrediggoConfig->features_ids))) {
                     $attribute = $dom->createElement('attribute');
                     $root->appendChild($attribute);
                     $attName = $dom->createElement('attName');
                     $attName->appendChild($dom->createCDATASection($aProductFeature['name']));
                     $attribute->appendChild($attName);
                     $attValue = $dom->createElement('attValue');
                     $attValue->appendChild($dom->createCDATASection($aProductFeature['value']));
                     $attribute->appendChild($attValue);
                 }
             }
         }
         unset($aProductFeatures);
         $aAccessories = Product::getAccessoriesLight($id_lang, (int) $oProduct->id);
         if (sizeof($aAccessories)) {
             foreach ($aAccessories as $aAccessory) {
                 $attribute = $dom->createElement('attribute');
                 $root->appendChild($attribute);
                 $attName = $dom->createElement('attName');
                 $attName->appendChild($dom->createCDATASection('accessory'));
                 $attribute->appendChild($attName);
                 $attValue = $dom->createElement('attValue');
                 $attValue->appendChild($dom->createCDATASection((int) $aAccessory['id_product']));
                 $attribute->appendChild($attValue);
             }
         }
         unset($aAccessories);
         $sReturn .= $dom->saveXML($root);
     }
     unset($dom);
     unset($oProduct);
     return $sReturn;
 }
 /**
  * Get and assign attributes combinations informations
  */
 protected function assignAttributesCombinations()
 {
     $attributes_combinations = Product::getAttributesInformationsByProduct($this->product->id);
     if (is_array($attributes_combinations) && count($attributes_combinations)) {
         foreach ($attributes_combinations as &$ac) {
             foreach ($ac as &$val) {
                 $val = str_replace('-', '_', Tools::link_rewrite(str_replace(array(',', '.'), '-', $val)));
             }
         }
     } else {
         $attributes_combinations = array();
     }
     $this->context->smarty->assign('attributesCombinations', $attributes_combinations);
 }
Example #5
0
 public static function indexation($id_product = false, $update = false)
 {
     $id_lang = Cmsearch::getLangId();
     $convermax = new ConvermaxAPI();
     if (!$id_product) {
         if (!$convermax->batchStart()) {
             return false;
         }
     }
     $start = 0;
     while ($products = Cmsearch::getProductsToIndex($id_lang, $start, 200, $id_product)) {
         $start = $start + 200;
         if (count($products) == 0) {
             break;
         }
         $products_array = array();
         $products_count = count($products);
         for ($i = 0; $i < $products_count; $i++) {
             if ($products[$i]['features']) {
                 foreach ($products[$i]['features'] as $feature) {
                     $f_name = 'f_' . $convermax->sanitize($feature['name']);
                     $products[$i][$f_name][] = $feature['value'];
                 }
                 unset($products[$i]['features']);
             }
             foreach ($products[$i] as $key => $val) {
                 if (is_array($val)) {
                     foreach ($val as $k => $v) {
                         if (is_array($v)) {
                             unset($products[$i][$key]);
                         }
                     }
                 }
             }
             $img_id = Product::getCover($products[$i]['id_product']);
             $link = new Link();
             $img_link = $link->getImageLink($products[$i]['link_rewrite'], $img_id['id_image'], ImageType::getFormatedName('small'));
             $products[$i]['img_link'] = str_replace(Tools::getHttpHost(), '', $img_link);
             $products[$i]['link'] = str_replace(Tools::getHttpHost(true), '', $products[$i]['link']);
             $cat_full = Product::getProductCategoriesFull($products[$i]['id_product']);
             $category_full = array();
             $home_category = Configuration::get('PS_HOME_CATEGORY');
             foreach ($cat_full as $cat) {
                 $category = new Category($cat['id_category']);
                 $categories = $category->getParentsCategories();
                 $c_full = array();
                 foreach ($categories as $cats) {
                     if ($cats['id_category'] != $home_category) {
                         $c_full[] = $cats['name'];
                     }
                 }
                 if (!empty($c_full)) {
                     $category_full[] = implode('>', array_reverse($c_full));
                 }
             }
             $products[$i]['category_full'] = $category_full;
             $attributes = Product::getAttributesInformationsByProduct($products[$i]['id_product']);
             if (!empty($attributes)) {
                 foreach ($attributes as $attribute) {
                     $a_name = 'a_' . $convermax->sanitize($attribute['group']);
                     $products[$i][$a_name][] = $attribute['attribute'];
                 }
             }
             if (!in_array($products[$i]['id_product'], $products_array)) {
                 $products_array[] = (int) $products[$i]['id_product'];
             }
         }
         if ($update) {
             if (!$convermax->update($products)) {
                 return false;
             }
         } elseif ($id_product) {
             if (!$convermax->add($products)) {
                 return false;
             }
         } elseif (!$convermax->batchAdd($products)) {
             return false;
         }
         if ($id_product) {
             break;
         }
     }
     if (!$id_product) {
         if (!$convermax->batchEnd()) {
             return false;
         }
     }
     return true;
 }
 /**
  * prepare attribute groups
  *
  * @return array
  */
 protected function prepareAttributeGroups()
 {
     $result = array();
     if ($this->currentProduct->hasAttributes()) {
         //function getAttributesInformationsByProduct available from version 1.5.0.1
         if (version_compare(_PS_VERSION_, '1.5.0.1', '<')) {
             $attributes = BWProduct::getAttributesInformationsByProduct($this->currentProduct->id, $this->getPlugin()->getLanguageId());
         } else {
             $attributes = Product::getAttributesInformationsByProduct($this->currentProduct->id);
         }
         $addedGroup = array();
         foreach ($attributes as $attribute) {
             if (!in_array($attribute['id_attribute_group'], $addedGroup)) {
                 $attributeItem = new Shopgate_Model_Catalog_AttributeGroup();
                 $attributeItem->setUid($attribute['id_attribute_group']);
                 $attributeItem->setLabel($attribute['group']);
                 $result[] = $attributeItem;
                 $addedGroup[] = $attribute['id_attribute_group'];
             }
         }
     }
     return $result;
 }