Example #1
0
 private function insertAttributes($text, \Ess\M2ePro\Model\Magento\Product $magentoProduct)
 {
     preg_match_all("/#([a-zA-Z_0-9]+?)#/", $text, $matches);
     if (!count($matches[0])) {
         return $text;
     }
     $search = array();
     $replace = array();
     foreach ($matches[1] as $attributeCode) {
         $value = $magentoProduct->getAttributeValue($attributeCode);
         if (!is_array($value) && $value != '') {
             if ($attributeCode == 'description') {
                 $value = $this->normalizeDescription($value);
             } elseif ($attributeCode == 'weight') {
                 $value = (double) $value;
             } elseif (in_array($attributeCode, array('price', 'special_price'))) {
                 $value = $magentoProduct->getProduct()->getFormatedPrice();
             }
             $search[] = '#' . $attributeCode . '#';
             $replace[] = $value;
         } else {
             $search[] = '#' . $attributeCode . '#';
             $replace[] = '';
         }
     }
     $text = str_replace($search, $replace, $text);
     return $text;
 }