private function insertMediaGalleries($text, Ess_M2ePro_Model_MagentoProduct $magentoProduct)
 {
     preg_match_all("/#media_gallery\\[(.*?)\\]#/", $text, $matches);
     if (!count($matches[0])) {
         return $text;
     }
     $blockObj = Mage::getSingleton('core/layout')->createBlock('M2ePro/adminhtml_descriptionTemplates_templates_gallery');
     $search = array();
     $replace = array();
     $attributeCounter = 0;
     foreach ($matches[0] as $key => $match) {
         $tempMediaGalleryAttributes = explode(',', $matches[1][$key]);
         $realMediaGalleryAttributes = array();
         for ($i = 0; $i < 7; $i++) {
             if (!isset($tempMediaGalleryAttributes[$i])) {
                 $realMediaGalleryAttributes[$i] = '';
             } else {
                 $realMediaGalleryAttributes[$i] = $tempMediaGalleryAttributes[$i];
             }
         }
         $imagesQty = (int) $realMediaGalleryAttributes[5];
         if ($imagesQty == self::IMAGES_QTY_ALL) {
             $imagesQty = $realMediaGalleryAttributes[3] == self::IMAGES_MODE_GALLERY ? 100 : 25;
         }
         $galleryImagesLinks = $magentoProduct->getGalleryImagesLinks($imagesQty);
         if (!count($galleryImagesLinks)) {
             $search = $matches[0];
             $replace = '';
             break;
         }
         if (!in_array($realMediaGalleryAttributes[4], array(self::LAYOUT_MODE_ROW, self::LAYOUT_MODE_COLUMN))) {
             $realMediaGalleryAttributes[4] = self::LAYOUT_MODE_ROW;
         }
         $data = array('width' => (int) $realMediaGalleryAttributes[0], 'height' => (int) $realMediaGalleryAttributes[1], 'margin' => (int) $realMediaGalleryAttributes[2], 'linked_mode' => (int) $realMediaGalleryAttributes[3], 'layout' => $realMediaGalleryAttributes[4], 'gallery_hint' => trim($realMediaGalleryAttributes[6], '"'), 'images_count' => count($galleryImagesLinks), 'image_counter' => 0);
         $tempHtml = '';
         $attributeCounter++;
         foreach ($galleryImagesLinks as $imageLink) {
             $data['image_counter']++;
             $data['attribute_counter'] = $attributeCounter;
             $data['src'] = $imageLink;
             $tempHtml .= $blockObj->addData($data)->toHtml();
         }
         $search[] = $match;
         $replace[] = preg_replace('/\\s{2,}/', '', $tempHtml);
     }
     $text = str_replace($search, $replace, $text);
     return $text;
 }
Example #2
0
 protected function getBundleProductOptions(Ess_M2ePro_Model_MagentoProduct $magentoProduct, array $ebayItemOptions = array())
 {
     $bundleOptions = $magentoProduct->getProductVariationsForOrder();
     if (!count($ebayItemOptions)) {
         // Variation info unavailable - return first value for each required option
         $firstOptions = array();
         foreach ($bundleOptions as $option) {
             $firstOptions[$option['option_id']] = $option['values'][0]['value_id'];
         }
         // Parser hack -> Mage::helper('M2ePro')->__('The eBay item is listed as simple (variations are ignored). As required options are missing, the first options value(s) is used to create Magento Order.');
         count($firstOptions) && $this->getOrder()->addWarningLogMessage('The eBay item is listed as simple (variations are ignored). As required options are missing, the first options value(s) is used to create Magento Order.');
         return $firstOptions;
     }
     $mappedOptions = array();
     foreach ($bundleOptions as $option) {
         if (count($option['values']) == 1) {
             $mappedOptions[$option['option_id']] = $option['values'][0]['value_id'];
             continue;
         }
         if (!isset($ebayItemOptions[$option['default_title']])) {
             continue;
         }
         foreach ($option['values'] as $value) {
             if ($ebayItemOptions[$option['default_title']] == $value['name']) {
                 $mappedOptions[$option['option_id']] = $value['value_id'];
                 break;
             }
         }
     }
     return $mappedOptions;
 }