Пример #1
0
 private function match()
 {
     $this->validate();
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Matcher\Attribute $attributeMatcher */
     $attributeMatcher = $this->modelFactory->getObject('Amazon\\Listing\\Product\\Variation\\Matcher\\Attribute');
     if (!is_null($this->magentoProduct)) {
         if ($this->magentoProduct->isGroupedType()) {
             $this->matchedTheme = null;
             return $this;
         }
         $attributeMatcher->setMagentoProduct($this->magentoProduct);
     }
     if (!empty($this->sourceAttributes)) {
         $attributeMatcher->setSourceAttributes($this->sourceAttributes);
         $attributeMatcher->canUseDictionary(false);
     }
     foreach ($this->themes as $themeName => $themeAttributes) {
         $attributeMatcher->setDestinationAttributes($themeAttributes['attributes']);
         if ($attributeMatcher->isAmountEqual() && $attributeMatcher->isFullyMatched()) {
             $this->matchedTheme = $themeName;
             break;
         }
     }
     return $this;
 }
Пример #2
0
 private function getDescription(\Ess\M2ePro\Model\Magento\Product $magentoProduct, \Ess\M2ePro\Model\Listing\Product $listingProduct = NULL)
 {
     $descriptionTemplateData = $this->_getSession()->getTemplateData();
     $descriptionModeProduct = \Ess\M2ePro\Model\Ebay\Template\Description::DESCRIPTION_MODE_PRODUCT;
     $descriptionModeShort = \Ess\M2ePro\Model\Ebay\Template\Description::DESCRIPTION_MODE_SHORT;
     $descriptionModeCustom = \Ess\M2ePro\Model\Ebay\Template\Description::DESCRIPTION_MODE_CUSTOM;
     if ($descriptionTemplateData['description_mode'] == $descriptionModeProduct) {
         $description = $magentoProduct->getProduct()->getDescription();
     } elseif ($descriptionTemplateData['description_mode'] == $descriptionModeShort) {
         $description = $magentoProduct->getProduct()->getShortDescription();
     } elseif ($descriptionTemplateData['description_mode'] == $descriptionModeCustom) {
         $description = $descriptionTemplateData['description_template'];
     } else {
         $description = '';
     }
     if (empty($description)) {
         return $description;
     }
     $renderer = $this->getHelper('Module\\Renderer\\Description');
     $description = $renderer->parseTemplate($description, $magentoProduct);
     if (!is_null($listingProduct)) {
         /** @var \Ess\M2ePro\Model\Ebay\Listing\Product\Description\Renderer $renderer */
         $renderer = $this->modelFactory->getObject('Ebay\\Listing\\Product\\Description\\Renderer');
         $renderer->setListingProduct($listingProduct->getChildObject());
         $description = $renderer->parseTemplate($description);
     }
     $this->addWatermarkInfoToDescriptionIfNeed($description);
     return $description;
 }
Пример #3
0
 protected function getBundleProductDynamicSpecialValue(Product $product)
 {
     if ($this->getIsSalePrice() && !$product->isSpecialPriceActual()) {
         return 0;
     }
     return parent::getBundleProductDynamicSpecialValue($product);
 }
Пример #4
0
 /**
  * @param \Ess\M2ePro\Model\Magento\Product $magentoProduct
  * @return \Ess\M2ePro\Model\Ebay\Template\Shipping\Calculated\Source
  */
 public function getSource(\Ess\M2ePro\Model\Magento\Product $magentoProduct)
 {
     $productId = $magentoProduct->getProductId();
     if (!empty($this->shippingCalculatedSourceModels[$productId])) {
         return $this->shippingCalculatedSourceModels[$productId];
     }
     $this->shippingCalculatedSourceModels[$productId] = $this->modelFactory->getObject('Ebay\\Template\\Shipping\\Calculated\\Source');
     $this->shippingCalculatedSourceModels[$productId]->setMagentoProduct($magentoProduct);
     $this->shippingCalculatedSourceModels[$productId]->setShippingCalculatedTemplate($this);
     return $this->shippingCalculatedSourceModels[$productId];
 }
Пример #5
0
 /**
  * @param \Ess\M2ePro\Model\Magento\Product $magentoProduct
  * @return \Ess\M2ePro\Model\Ebay\Template\Category\Specific\Source
  */
 public function getSource(\Ess\M2ePro\Model\Magento\Product $magentoProduct)
 {
     $productId = $magentoProduct->getProductId();
     if (!empty($this->categorySpecificSourceModels[$productId])) {
         return $this->categorySpecificSourceModels[$productId];
     }
     $this->categorySpecificSourceModels[$productId] = $this->modelFactory->getObject('Ebay\\Template\\Category\\Specific\\Source');
     $this->categorySpecificSourceModels[$productId]->setMagentoProduct($magentoProduct);
     $this->categorySpecificSourceModels[$productId]->setCategorySpecificTemplate($this);
     return $this->categorySpecificSourceModels[$productId];
 }
Пример #6
0
 public function getMagentoProduct()
 {
     if (is_null($this->getProductId())) {
         return NULL;
     }
     if (is_null($this->magentoProduct)) {
         $this->magentoProduct = $this->modelFactory->getObject('Magento\\Product');
         $this->magentoProduct->setStoreId($this->getOrder()->getStoreId())->setProductId($this->getProductId());
     }
     return $this->magentoProduct;
 }
Пример #7
0
 private function getSourceOptionNames($sourceOption)
 {
     $magentoOptionNames = $this->magentoProduct->getVariationInstance()->getTitlesVariationSet();
     $resultNames = array();
     foreach ($sourceOption as $attribute => $option) {
         $names = array();
         if (isset($magentoOptionNames[$attribute])) {
             $names = $magentoOptionNames[$attribute]['values'][$option];
         }
         $resultNames[$attribute] = $this->prepareOptionNames($option, $names);
     }
     return $resultNames;
 }
Пример #8
0
 private function getSourceAttributesData()
 {
     if (!is_null($this->magentoProduct)) {
         $magentoAttributesNames = $this->magentoProduct->getVariationInstance()->getTitlesVariationSet();
         $magentoStandardVariations = $this->magentoProduct->getVariationInstance()->getVariationsTypeStandard();
         $resultData = array();
         foreach (array_keys($magentoStandardVariations['set']) as $attribute) {
             $titles = array();
             if (isset($magentoAttributesNames[$attribute])) {
                 $titles = $magentoAttributesNames[$attribute]['titles'];
             }
             $resultData[$attribute] = $titles;
         }
         return $resultData;
     }
     return array_fill_keys($this->getSourceAttributes(), array());
 }
Пример #9
0
 private function insertMediaGalleries($text, \Ess\M2ePro\Model\Magento\Product $magentoProduct)
 {
     preg_match_all("/#media_gallery\\[(.*?)\\]#/", $text, $matches);
     if (!count($matches[0])) {
         return $text;
     }
     $blockObj = $this->layout->createBlock('Ess\\M2ePro\\Block\\Adminhtml\\Renderer\\Description\\Gallery');
     $search = array();
     $replace = array();
     $attributeCounter = 0;
     foreach ($matches[0] as $key => $match) {
         $tempMediaGalleryAttributes = explode(',', $matches[1][$key]);
         $realMediaGalleryAttributes = array();
         for ($i = 0; $i < 8; $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], '"'), 'watermark' => (int) $realMediaGalleryAttributes[7], '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;
 }
Пример #10
0
 /**
  * @param \Ess\M2ePro\Model\Magento\Product $magentoProduct
  * @return \Ess\M2ePro\Model\Ebay\Template\SellingFormat\Source
  */
 public function getSource(\Ess\M2ePro\Model\Magento\Product $magentoProduct)
 {
     $productId = $magentoProduct->getProductId();
     if (!empty($this->sellingSourceModels[$productId])) {
         return $this->sellingSourceModels[$productId];
     }
     $this->sellingSourceModels[$productId] = $this->modelFactory->getObject('Ebay\\Template\\SellingFormat\\Source');
     $this->sellingSourceModels[$productId]->setMagentoProduct($magentoProduct);
     $this->sellingSourceModels[$productId]->setSellingFormatTemplate($this->getParentObject());
     return $this->sellingSourceModels[$productId];
 }
Пример #11
0
 /**
  * @param \Ess\M2ePro\Model\Magento\Product $magentoProduct
  * @return \Ess\M2ePro\Model\Amazon\Template\Description\Source
  */
 public function getSource(\Ess\M2ePro\Model\Magento\Product $magentoProduct)
 {
     $productId = $magentoProduct->getProductId();
     if (!empty($this->descriptionSourceModels[$productId])) {
         return $this->descriptionSourceModels[$productId];
     }
     $this->descriptionSourceModels[$productId] = $this->modelFactory->getObject('Amazon\\Template\\Description\\Source');
     $this->descriptionSourceModels[$productId]->setMagentoProduct($magentoProduct);
     $this->descriptionSourceModels[$productId]->setDescriptionTemplate($this->getParentObject());
     return $this->descriptionSourceModels[$productId];
 }
Пример #12
0
 protected function getBundleProductDynamicValue(Product $product)
 {
     $value = 0;
     $variationsData = $product->getVariationInstance()->getVariationsTypeStandard();
     foreach ($variationsData['variations'] as $variation) {
         $variationValue = 0;
         foreach ($variation as $option) {
             /** @var $childProduct Product */
             $childProduct = $this->modelFactory->getObject('Magento\\Product')->setProductId($option['product_id']);
             $optionValue = (double) $childProduct->getSpecialPrice();
             $optionValue <= 0 && ($optionValue = (double) $childProduct->getPrice());
             $variationValue += $optionValue;
         }
         if ($variationValue < $value || $value == 0) {
             $value = $variationValue;
         }
     }
     return $this->convertValueFromStoreToMarketplace($value);
 }
Пример #13
0
 private function changeProductQty(\Ess\M2ePro\Model\Magento\Product $magentoProduct, \Ess\M2ePro\Model\Magento\Product\StockItem $magentoStockItem, $action, $qty)
 {
     $result = true;
     switch ($action) {
         case self::ACTION_ADD:
             $magentoStockItem->addQty($qty, false);
             break;
         case self::ACTION_SUB:
             try {
                 $magentoStockItem->subtractQty($qty, false);
             } catch (\Exception $e) {
                 $result = false;
                 $this->order->addErrorLog('QTY for Product "%name%" cannot be reserved. Reason: %msg%', array('!name' => $magentoProduct->getName(), 'msg' => $e->getMessage()));
             }
             break;
     }
     return $result;
 }
Пример #14
0
 /**
  * @param \Ess\M2ePro\Model\Magento\Product $magentoProduct
  * @return \Ess\M2ePro\Model\Amazon\Listing\Source
  */
 public function getSource(\Ess\M2ePro\Model\Magento\Product $magentoProduct)
 {
     $productId = $magentoProduct->getProductId();
     if (!empty($this->listingSourceModels[$productId])) {
         return $this->listingSourceModels[$productId];
     }
     $this->listingSourceModels[$productId] = $this->modelFactory->getObject('Amazon\\Listing\\Source');
     $this->listingSourceModels[$productId]->setMagentoProduct($magentoProduct);
     $this->listingSourceModels[$productId]->setListing($this->getParentObject());
     return $this->listingSourceModels[$productId];
 }