/** * {uri} * @param \Wyomind\Simplegoogleshopping\Model\Feeds $model * @param array $options * @param \Magento\Catalog\Model\Product $product * @param string $reference * @return string */ public function uri($model, $options, $product, $reference) { unset($options); $item = $model->checkReference($reference, $product); if ($item == null) { return ""; } if ($item->getRequest_path()) { // shortest if ($model->urlRewrites == \Wyomind\SimpleGoogleShopping\Model\Config\UrlRewrite::SHORTEST_URL) { $arr = explode(",", $item->getRequest_path()); usort($arr, ['\\Wyomind\\SimpleGoogleShopping\\Helper\\Attributes', 'cmp']); $value = array_pop($arr); } elseif ($model->urlRewrites == \Wyomind\SimpleGoogleShopping\Model\Config\UrlRewrite::LONGEST_URL) { // longest $arr = explode(",", $item->getRequest_path()); usort($arr, ['\\Wyomind\\SimpleGoogleShopping\\Helper\\Attributes', 'cmp']); $value = array_shift($arr); } else { $value = $item->getRequest_path(); } } else { $value = str_replace($model->storeUrl, '', $item->getProductUrl()); } return $value; }
/** * {image} attribute processing * @param \Wyomind\Simplegoogleshopping\Model\Feeds $model * @param array $options * @param \Magento\Catalog\Model\Product $product * @param string $reference * @return string product's image */ public function imageLink($model, $options, $product, $reference) { $item = $model->checkReference($reference, $product); if ($item == null) { return ""; } $baseImage = $item->getImage(); $value = ""; if (!isset($options['index']) || $options['index'] == 0) { if ($item->getImage() != null && $item->getImage() != "" && $item->getImage() != 'no_selection') { $path = 'catalog/product/' . $item->getImage(); $value = $model->baseImg . str_replace('//', '/', $path); } else { if ($model->defaultImage != "") { $value = $model->baseImg . '/catalog/product/placeholder/' . $model->defaultImage; } } } elseif (isset($model->gallery[$item->getId()]['src'][$options['index'] - 1]) && $options['index'] > 0) { if ($model->gallery[$item->getId()]['src'][$options['index'] - 1] != $baseImage) { $path = 'catalog/product/' . $model->gallery[$item->getId()]['src'][$options['index'] - 1]; $value = $model->baseImg . str_replace('//', '/', $path); } } return $value; }
/** * {final_price} attribute processing * @param \Wyomind\Simplegoogleshopping\Model\Feeds $model * @param array $options * @param \Magento\Catalog\Model\Product $product * @param string $reference * @return string formatted version of the final price */ public function finalPrice($model, $options, $product, $reference) { $item = $model->checkReference($reference, $product); if ($item == null) { return ""; } $price = $item->getFinalPrice(); $value = $this->applyTaxThenCurrency($model, $item->getTaxClassId(), $price, $options, $reference); return $value; }
/** * All other attributes processing * @param \Wyomind\Simplegoogleshopping\Model\Feeds $model * @param \Magento\Catalog\Model\Product $product * @param string $reference * @return string the attribute value */ public function productAttribute($model, $attribute, $product, $reference) { $item = $model->checkReference($reference, $product); if ($item == null) { return ""; } $methodName = "get" . str_replace(' ', '', ucwords(trim($attribute))); if (in_array($attribute, $model->listOfAttributes)) { if (in_array($model->listOfAttributesType[$attribute], ['select', 'multiselect'])) { $val = $item->{$methodName}(); $vals = explode(',', $val); /* multiselect */ if (count($vals) > 1) { $value = []; foreach ($vals as $v) { if (isset($model->attributesLabelsList[$v][$model->params['store_id']])) { $value[] = $model->attributesLabelsList[$v][$model->params['store_id']]; } else { if (isset($model->attributesLabelsList[$v][0])) { $value[] = $model->attributesLabelsList[$v][0]; } } } } else { /* select */ if (isset($model->attributesLabelsList[$vals[0]][$model->params['store_id']])) { $value = $model->attributesLabelsList[$vals[0]][$model->params['store_id']]; } else { if (isset($model->attributesLabelsList[$vals[0]][0])) { $value = $model->attributesLabelsList[$vals[0]][0]; } } } } else { $value = $item->{$methodName}(); } } /* Recuperer une valeur de taux de change */ if (isset($model->listOfCurrencies[$attribute])) { $value = $model->listOfCurrencies[$attribute]; } if (!isset($value)) { $value = ""; } /* enlever les caractères invalides */ $valueCleaned = preg_replace('/' . '[\\x00-\\x1F\\x7F]' . '|[\\x00-\\x7F][\\x80-\\xBF]+' . '|([\\xC0\\xC1]|[\\xF0-\\xFF])[\\x80-\\xBF]*' . '|[\\xC2-\\xDF]((?![\\x80-\\xBF])|[\\x80-\\xBF]{2,})' . '|[\\xE0-\\xEF](([\\x80-\\xBF](?![\\x80-\\xBF]))|' . '(?![\\x80-\\xBF]{2})|[\\x80-\\xBF]{3,})' . '/S', ' ', $value); $value = str_replace('™', '', $valueCleaned); return $value; }
/** * {sc_condition} attribute processing * @param \Wyomind\Simplegoogleshopping\Model\Feeds $model * @param array $options * @param \Magento\Catalog\Model\Product $product * @param string $reference * @return type */ public function scCondition($model, $options, $product, $reference) { unset($options); $item = $model->checkReference($reference, $product); if ($item == null) { return ""; } $condition = stristr($item->getName(), "refurbished") ? 'refurbished' : 'new'; $value = $condition; return $value; }
/** * {category_mapping} attribute processing * @param \Wyomind\Simplegoogleshopping\Model\Feeds $model * @param array $options * @param \Magento\Catalog\Model\Product $product * @param string $reference * @return string mapped category */ public function categoryMapping($model, $options, $product, $reference) { $item = $model->checkReference($reference, $product); if ($item == null) { return ""; } $num = isset($options["index"]) ? $options["index"] : 0; $value = ""; $n = 0; foreach ($item->getCategoryIds() as $key => $category) { if (isset($model->categoriesMapping[$category])) { if ($n == $num) { $value .= $model->categoriesMapping[$category]; break; } $n++; } } return $value; }
/** * {qty} attribute processing * @param \Wyomind\Simplegoogleshopping\Model\Feeds $model * @param array $options * @param \Magento\Catalog\Model\Product $product * @param string $reference * @return string quantity of the product */ public function qty($model, $options, $product, $reference) { $item = $model->checkReference($reference, $product); if ($item == null) { return ""; } $float = !isset($options['float']) ? 0 : $options['float']; if ($product->getTypeID() == "configurable") { $value = number_format($model->configurableQty[$product->getId()], $float, '.', ''); } elseif ($reference == "configurable") { $value = number_format($model->configurableQty[$item->getId()], $float, '.', ''); } else { $value = number_format($item->getQty(), $float, '.', ''); } return $value; }