/**
  * {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;
 }
Example #2
0
 /**
  * {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;
 }
 /**
  * {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;
 }
Example #4
0
 /**
  * Generates the html error report summary after a data feed generation
  * @param \Wyomind\Simplegoogleshopping\Model\Feeds $row
  * @return string
  */
 public function generationStats($row)
 {
     $fileName = preg_replace('/^\\//', '', $row->getSimplegoogleshoppingPath() . ($row->getSimplegoogleshoppingPath() == "/" ? "" : "/") . $row->getSimplegoogleshoppingFilename());
     $this->_storeManager->setCurrentStore($row->getStoreId());
     $baseurl = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, false);
     $rootdir = $this->_list->getPath(\Magento\Framework\App\Filesystem\DirectoryList::ROOT);
     $url = $baseurl . $fileName;
     $url = preg_replace('/([^\\:])\\/\\//', '$1/', $url);
     if ($this->_io->fileExists($rootdir . "/" . $fileName)) {
         $report = unserialize($row->getSimplegoogleshoppingReport());
         $errors = 0;
         if (isset($report['required'])) {
             $errors += count($report['required']);
         }
         if (isset($report['toolong'])) {
             $errors += count($report['toolong']);
         }
         if (isset($report['toomany'])) {
             $errors += count($report['toomany']);
         }
         if (isset($report['invalid'])) {
             $errors += count($report['invalid']);
         }
         $warnings = 0;
         if (isset($report['recommended'])) {
             $warnings += count($report['recommended']);
         }
         $time = $report['stats'][1];
         $items = $report['stats'][0];
         $stats = $items . __(' product') . ($items > 1 ? "s" : "") . __(" exported in ") . $this->_coreHelper->getDuration($time);
         if ($report == null) {
             return '<a href="' . $url . '?r=' . time() . '" target="_blank">' . $url . '</a><br>' . "[ " . __('The data feed must be generated prior to any report.') . " ]";
         } elseif (!($errors + $warnings)) {
             return '<a href="' . $url . '?r=' . time() . '" target="_blank">' . $url . '</a><br>' . '[ ' . $stats . ", " . __('no error detected') . ' ]';
         } else {
             return '<a href="' . $url . '?r=' . time() . '" target="_blank">' . $url . '</a><br>' . '[ ' . $stats . ", " . $errors . " " . __('error') . ($errors > 1 ? "s" : null) . ', ' . $warnings . ' ' . __('warning') . ($warnings > 1 ? "s" : null) . ' ]';
         }
     } else {
         return $url . "<br> [ " . __('no report available') . " ]";
     }
 }
 /**
  * {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;
 }
Example #6
0
 /**
  * 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('&#153;', '', $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;
 }