Example #1
0
 private function insertImages($text, \Ess\M2ePro\Model\Magento\Product $magentoProduct)
 {
     preg_match_all("/#image\\[(.*?)\\]#/", $text, $matches);
     if (!count($matches[0])) {
         return $text;
     }
     $imageLink = $magentoProduct->getImageLink('image');
     $blockObj = $this->layout->createBlock('Ess\\M2ePro\\Block\\Adminhtml\\Renderer\\Description\\Image');
     $search = array();
     $replace = array();
     foreach ($matches[0] as $key => $match) {
         $tempImageAttributes = explode(',', $matches[1][$key]);
         $realImageAttributes = array();
         for ($i = 0; $i < 6; $i++) {
             if (!isset($tempImageAttributes[$i])) {
                 $realImageAttributes[$i] = 0;
             } else {
                 $realImageAttributes[$i] = (int) $tempImageAttributes[$i];
             }
         }
         $tempImageLink = $realImageAttributes[5] == 0 ? $imageLink : $magentoProduct->getGalleryImageLink($realImageAttributes[5]);
         $data = array('width' => $realImageAttributes[0], 'height' => $realImageAttributes[1], 'margin' => $realImageAttributes[2], 'linked_mode' => $realImageAttributes[3], 'watermark' => $realImageAttributes[4], 'src' => $tempImageLink);
         $search[] = $match;
         $replace[] = $tempImageLink == '' ? '' : preg_replace('/\\s{2,}/', '', $blockObj->addData($data)->toHtml());
     }
     $text = str_replace($search, $replace, $text);
     return $text;
 }