Example #1
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  */
 public function process(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     if (!$listingProduct->getMagentoProduct()->isProductWithVariations()) {
         return;
     }
     $rawMagentoVariations = $listingProduct->getMagentoProduct()->getVariationInstance()->getVariationsTypeStandard();
     $rawMagentoVariations = $this->getHelper('Component\\Ebay')->reduceOptionsForVariations($rawMagentoVariations);
     $rawMagentoVariations = $this->validateExistenceConditions($rawMagentoVariations, $listingProduct);
     $rawMagentoVariations = $this->validateLimitsConditions($rawMagentoVariations, $listingProduct);
     $magentoVariations = $this->prepareMagentoVariations($rawMagentoVariations);
     if (!$listingProduct->getMagentoProduct()->isSimpleType()) {
         $this->inspectAndFixProductOptionsIds($listingProduct, $magentoVariations);
     }
     $currentVariations = $this->prepareCurrentVariations($listingProduct->getVariations(true));
     $addedVariations = $this->getAddedVariations($magentoVariations, $currentVariations);
     $deletedVariations = $this->getDeletedVariations($magentoVariations, $currentVariations);
     $this->addNewVariations($listingProduct, $addedVariations);
     $this->markAsDeletedVariations($deletedVariations);
     $this->saveVariationsData($listingProduct, $rawMagentoVariations);
 }
Example #2
0
 private function checkVariationStructureChanges(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Manager $variationManager */
     $variationManager = $listingProduct->getChildObject()->getVariationManager();
     if ($variationManager->isRelationParentType()) {
         $this->parentListingsProductsForProcessing[$listingProduct->getId()] = $listingProduct;
         return;
     }
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Manager\PhysicalUnit $typeModel */
     $typeModel = $variationManager->getTypeModel();
     if (!$listingProduct->getMagentoProduct()->isSimpleType()) {
         $typeModel->inspectAndFixProductOptionsIds();
     }
     if (!$typeModel->isActualProductAttributes()) {
         if ($variationManager->isRelationChildType()) {
             $this->parentListingsProductsForProcessing[$typeModel->getParentListingProduct()->getId()] = $typeModel->getParentListingProduct();
             return;
         }
         /** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Manager\Type\Individual $typeModel */
         $typeModel->resetProductVariation();
         return;
     }
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Manager\PhysicalUnit $typeModel */
     if ($typeModel->isVariationProductMatched() && !$typeModel->isActualProductVariation()) {
         if ($variationManager->isRelationChildType()) {
             /** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Manager\Type\Relation\ChildRelation $typeModel */
             $this->parentListingsProductsForProcessing[$typeModel->getParentListingProduct()->getId()] = $typeModel->getParentListingProduct();
             return;
         }
         $typeModel->unsetProductVariation();
     }
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Manager\Type\Relation\ChildRelation $typeModel */
     if ($variationManager->isRelationChildType() && $typeModel->getParentTypeModel()->getVirtualChannelAttributes()) {
         if (!$typeModel->getParentTypeModel()->isActualVirtualChannelAttributes()) {
             $this->parentListingsProductsForProcessing[$typeModel->getParentListingProduct()->getId()] = $typeModel->getParentListingProduct();
         }
     }
 }
Example #3
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @return bool
  * @throws \Ess\M2ePro\Model\Exception
  * @throws \Ess\M2ePro\Model\Exception\Logic
  */
 public function isMeetStopRequirements(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     if (!$listingProduct->isListed() || $listingProduct->isBlocked()) {
         return false;
     }
     if (!$listingProduct->isStoppable()) {
         return false;
     }
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product $amazonListingProduct */
     $amazonListingProduct = $listingProduct->getChildObject();
     $variationManager = $amazonListingProduct->getVariationManager();
     if ($variationManager->isVariationProduct()) {
         if ($variationManager->isRelationParentType()) {
             return false;
         }
     }
     if ($listingProduct->isSetProcessingLock('in_action')) {
         return false;
     }
     $amazonSynchronizationTemplate = $amazonListingProduct->getAmazonSynchronizationTemplate();
     $variationResource = $this->activeRecordFactory->getObject('Listing\\Product\\Variation')->getResource();
     if ($amazonSynchronizationTemplate->isStopStatusDisabled()) {
         if (!$listingProduct->getMagentoProduct()->isStatusEnabled()) {
             return true;
         } else {
             if ($variationManager->isPhysicalUnit() && $variationManager->getTypeModel()->isVariationProductMatched()) {
                 $temp = $variationResource->isAllStatusesDisabled($listingProduct->getId(), $listingProduct->getListing()->getStoreId());
                 if (!is_null($temp) && $temp) {
                     return true;
                 }
             }
         }
     }
     if ($amazonSynchronizationTemplate->isStopOutOfStock()) {
         if (!$listingProduct->getMagentoProduct()->isStockAvailability()) {
             return true;
         } else {
             if ($variationManager->isPhysicalUnit() && $variationManager->getTypeModel()->isVariationProductMatched()) {
                 $temp = $variationResource->isAllDoNotHaveStockAvailabilities($listingProduct->getId(), $listingProduct->getListing()->getStoreId());
                 if (!is_null($temp) && $temp) {
                     return true;
                 }
             }
         }
     }
     if ($amazonSynchronizationTemplate->isStopWhenQtyMagentoHasValue()) {
         $productQty = (int) $amazonListingProduct->getQty(true);
         $typeQty = (int) $amazonSynchronizationTemplate->getStopWhenQtyMagentoHasValueType();
         $minQty = (int) $amazonSynchronizationTemplate->getStopWhenQtyMagentoHasValueMin();
         $maxQty = (int) $amazonSynchronizationTemplate->getStopWhenQtyMagentoHasValueMax();
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::STOP_QTY_LESS && $productQty <= $minQty) {
             return true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::STOP_QTY_MORE && $productQty >= $minQty) {
             return true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::STOP_QTY_BETWEEN && $productQty >= $minQty && $productQty <= $maxQty) {
             return true;
         }
     }
     if ($amazonSynchronizationTemplate->isStopWhenQtyCalculatedHasValue()) {
         $productQty = (int) $amazonListingProduct->getQty(false);
         $typeQty = (int) $amazonSynchronizationTemplate->getStopWhenQtyCalculatedHasValueType();
         $minQty = (int) $amazonSynchronizationTemplate->getStopWhenQtyCalculatedHasValueMin();
         $maxQty = (int) $amazonSynchronizationTemplate->getStopWhenQtyCalculatedHasValueMax();
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::STOP_QTY_LESS && $productQty <= $minQty) {
             return true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::STOP_QTY_MORE && $productQty >= $minQty) {
             return true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::STOP_QTY_BETWEEN && $productQty >= $minQty && $productQty <= $maxQty) {
             return true;
         }
     }
     return false;
 }
 protected function updateProduct(\Ess\M2ePro\Model\Listing\Product $listingProduct, array $response)
 {
     $productData = array();
     $descriptionTemplate = $listingProduct->getChildObject()->getDescriptionTemplate();
     $oldDescriptionTemplateId = $descriptionTemplate->getId();
     if (!isset($this->descriptionTemplatesIds[$oldDescriptionTemplateId]) && (trim($descriptionTemplate->getData('title_template')) != '#ebay_translated_title#' || trim($descriptionTemplate->getData('subtitle_template')) != '#ebay_translated_subtitle#' || trim($descriptionTemplate->getData('description_template')) != '#ebay_translated_description#')) {
         $data = $descriptionTemplate->getDataSnapshot();
         unset($data['id'], $data['update_date'], $data['create_date']);
         $data['title'] = $data['title'] . $this->getHelper('Module\\Translation')->__(' (Changed because Translation Service applied.)');
         $data['title_mode'] = \Ess\M2ePro\Model\Ebay\Template\Description::TITLE_MODE_CUSTOM;
         $data['title_template'] = '#ebay_translated_title#';
         $data['subtitle_mode'] = \Ess\M2ePro\Model\Ebay\Template\Description::SUBTITLE_MODE_CUSTOM;
         $data['subtitle_template'] = '#ebay_translated_subtitle#';
         $data['description_mode'] = \Ess\M2ePro\Model\Ebay\Template\Description::DESCRIPTION_MODE_CUSTOM;
         $data['description_template'] = '#ebay_translated_description#';
         $data['is_custom_template'] = 1;
         $newDescriptionTemplate = $this->modelFactory->getObject('Ebay\\Template\\Manager')->setTemplate(\Ess\M2ePro\Model\Ebay\Template\Manager::TEMPLATE_DESCRIPTION)->getTemplateBuilder()->build($data);
         $this->descriptionTemplatesIds[$oldDescriptionTemplateId] = $newDescriptionTemplate->getId();
     }
     if (isset($this->descriptionTemplatesIds[$oldDescriptionTemplateId])) {
         $productData['template_description_custom_id'] = $this->descriptionTemplatesIds[$oldDescriptionTemplateId];
         $productData['template_description_mode'] = \Ess\M2ePro\Model\Ebay\Template\Manager::MODE_CUSTOM;
     }
     $attributes = array('ebay_translated_title' => array('label' => 'Ebay Translated Title', 'type' => 'text'), 'ebay_translated_subtitle' => array('label' => 'Ebay Translated Subtitle', 'type' => 'text'), 'ebay_translated_description' => array('label' => 'Ebay Translated Description', 'type' => 'textarea'));
     $this->checkAndCreateMagentoAttributes($listingProduct->getMagentoProduct(), $attributes);
     $listingProduct->getMagentoProduct()->setAttributeValue('ebay_translated_title', $response['title'])->setAttributeValue('ebay_translated_subtitle', $response['subtitle'])->setAttributeValue('ebay_translated_description', $response['description']);
     //------------------------------
     $categoryPath = !is_null($response['category']['primary_id']) ? $this->getHelper('Component\\Ebay\\Category\\Ebay')->getPath((int) $response['category']['primary_id'], $this->params['marketplace_id']) : '';
     $response['category']['path'] = $categoryPath;
     if ($categoryPath) {
         $data = $this->activeRecordFactory->getObject('Ebay\\Template\\Category')->getDefaultSettings();
         $data['category_main_id'] = (int) $response['category']['primary_id'];
         $data['category_main_path'] = $categoryPath;
         $data['marketplace_id'] = $this->params['marketplace_id'];
         $data['specifics'] = $this->getSpecificsData($response['item_specifics']);
         $productData['template_category_id'] = $this->modelFactory->getObject('Ebay\\Template\\Category\\Builder')->build($data)->getId();
     } else {
         $response['category']['primary_id'] = null;
     }
     $additionalData = $listingProduct->getAdditionalData();
     $additionalData['translation_service']['to'] = array_merge($additionalData['translation_service']['to'], $response);
     $productData['additional_data'] = json_encode($additionalData);
     $listingProduct->addData($productData)->save();
     $listingProduct->getChildObject()->addData(array('translation_status' => \Ess\M2ePro\Model\Ebay\Listing\Product::TRANSLATION_STATUS_TRANSLATED, 'translated_date' => $this->getHelper('Data')->getCurrentGmtDate()))->save();
 }
Example #5
0
 protected function processAddedListingProduct(\Ess\M2ePro\Model\Listing\Product $listingProduct, array $params)
 {
     if (empty($params['template_description_id'])) {
         return;
     }
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product $amazonListingProduct */
     $amazonListingProduct = $listingProduct->getChildObject();
     if (!$amazonListingProduct->getVariationManager()->isRelationParentType()) {
         $amazonListingProduct->setData('template_description_id', $params['template_description_id']);
         $amazonListingProduct->setData('is_general_id_owner', \Ess\M2ePro\Model\Amazon\Listing\Product::IS_GENERAL_ID_OWNER_YES);
         $listingProduct->save();
         return;
     }
     $processor = $amazonListingProduct->getVariationManager()->getTypeModel()->getProcessor();
     if ($listingProduct->getMagentoProduct()->isBundleType() || $listingProduct->getMagentoProduct()->isSimpleTypeWithCustomOptions()) {
         $processor->process();
         return;
     }
     $detailsModel = $this->modelFactory->getObject('Amazon\\Marketplace\\Details');
     $detailsModel->setMarketplaceId($listingProduct->getListing()->getMarketplaceId());
     /** @var \Ess\M2ePro\Model\Template\Description $descriptionTemplate */
     $descriptionTemplate = $this->amazonFactory->getObjectLoaded('Template\\Description', $params['template_description_id']);
     /** @var \Ess\M2ePro\Model\Amazon\Template\Description $amazonDescriptionTemplate */
     $amazonDescriptionTemplate = $descriptionTemplate->getChildObject();
     $possibleThemes = $detailsModel->getVariationThemes($amazonDescriptionTemplate->getProductDataNick());
     $productAttributes = $amazonListingProduct->getVariationManager()->getTypeModel()->getProductAttributes();
     foreach ($possibleThemes as $theme) {
         if (count($theme['attributes']) != count($productAttributes)) {
             continue;
         }
         $amazonListingProduct->setData('template_description_id', $params['template_description_id']);
         $amazonListingProduct->setData('is_general_id_owner', \Ess\M2ePro\Model\Amazon\Listing\Product::IS_GENERAL_ID_OWNER_YES);
         break;
     }
     $listingProduct->save();
     $processor->process();
 }
Example #6
0
    public function callbackColumnActions($value, $row, $column, $isExport)
    {
        $assignText = $this->__('Assign');
        $iconWarningPath = $this->getSkinUrl('M2ePro/images/warning.png');
        $iconHelpPath = $this->getSkinUrl('M2ePro/images/i_notice.gif');
        if (!$this->listingProduct->getChildObject()->getVariationManager()->isVariationProduct() || $this->listingProduct->getChildObject()->getVariationManager()->isIndividualType()) {
            if (!$row->getData('is_variation_product')) {
                return <<<HTML
<a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
    {$this->productId}, '{$row->getData('general_id')}');">{$assignText}</a>
HTML;
            }
            if (!$row->getData('bad_parent')) {
                $msg = $this->__('Please select necessary Options for this Amazon Product to be able to assign ASIN/ISBN.');
                return <<<HTML
<span>
    <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
    {$this->getTooltipHtml($msg, 'map_link_error_icon_' . $row->getId())}
</span>
<div id="template_map_link_{$row->getId()}" style="display: none;">
<a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
    {$this->productId}, '%general_id%', '%options_data%'
);">{$assignText}</a>
</div>
HTML;
            }
        }
        if ($row->getData('is_variation_product') && !$row->getData('bad_parent')) {
            $msg = $this->__('Please map Amazon and Magento Attributes for this Amazon Product to be able to assign ASIN/ISBN.');
            $variations = $row->getData('variations');
            $destinationAttributes = array_keys($variations['set']);
            $this->matcherAttributes->setMagentoProduct($this->listingProduct->getMagentoProduct());
            $this->matcherAttributes->setDestinationAttributes($destinationAttributes);
            if ($this->matcherAttributes->isSourceAmountGreater()) {
                $msg = $this->__('Please map Magento and Amazon Attributes for this Amazon Product to be able to assign ASIN/ISBN.
                    Be careful, as the number of  Magento Attributes is more than the number of Attributes in Amazon
                    Parent Product. Thus you should select fixed Value for unmatched Magento Variational Attribute.');
            } else {
                if ($this->matcherAttributes->isDestinationAmountGreater()) {
                    $msg = $this->__('Please map Magento and Amazon Attributes for this Amazon Product to be able to assign ASIN/ISBN.
                    Be careful, as the number of Attributes in Amazon Parent Product is more than the number of
                    Magento Attributes. Thus you should select fixed Value for unmatched Amazon Variational Attribute.');
                }
            }
            return <<<HTML
<span>
    <div id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></div>&nbsp;
    {$this->getTooltipHtml($msg, 'map_link_error_icon_' . $row->getId())}
</span>
<div id="template_map_link_{$row->getId()}" style="display: none;">
<a href="javascript:void(0);" onclick="ListingGridHandlerObj.productSearchHandler.mapToGeneralId(
    {$this->productId}, '{$row->getData('general_id')}', '%options_data%'
);">{$assignText}</a>
</div>
HTML;
        }
        $msg = $this->__('This ASIN/ISBN cannot be assigned to selected Magento Product. <br/>
             This Amazon Product has no Variations. <br/>
             Only Amazon Parent/Child Products can be assigned in "All Variations" Mode.');
        if ($row->getData('is_variation_product') && $row->getData('bad_parent')) {
            $msg = $this->__('This ASIN/ISBN cannot be assigned to selected Magento Product. <br/>
                 Amazon Service (API) does not return all required information about this Amazon Product.');
        }
        return <<<HTML
<span>
    <span id="map_link_{$row->getId()}"><span style="color: #808080">{$assignText}</span></span>&nbsp;
    {$this->getTooltipHtml($msg, 'map_link_error_icon_' . $row->getId())}
</span>
HTML;
    }
Example #7
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @return bool
  * @throws \Ess\M2ePro\Model\Exception\Logic
  */
 public function isMeetStopRequirements(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     if (!$listingProduct->isListed()) {
         return false;
     }
     if (!$listingProduct->isStoppable() || $listingProduct->isHidden()) {
         return false;
     }
     /** @var \Ess\M2ePro\Model\Ebay\Listing\Product $ebayListingProduct */
     $ebayListingProduct = $listingProduct->getChildObject();
     $ebaySynchronizationTemplate = $ebayListingProduct->getEbaySynchronizationTemplate();
     if (!$ebayListingProduct->isSetCategoryTemplate()) {
         return false;
     }
     if ($listingProduct->isSetProcessingLock('in_action')) {
         return false;
     }
     $variationResource = $this->activeRecordFactory->getObject('Listing\\Product\\Variation')->getResource();
     if ($ebaySynchronizationTemplate->isStopStatusDisabled()) {
         if (!$listingProduct->getMagentoProduct()->isStatusEnabled()) {
             return true;
         } else {
             if ($ebayListingProduct->isVariationsReady()) {
                 $temp = $variationResource->isAllStatusesDisabled($listingProduct->getId(), $listingProduct->getListing()->getStoreId());
                 if (!is_null($temp) && $temp) {
                     return true;
                 }
             }
         }
     }
     if ($ebaySynchronizationTemplate->isStopOutOfStock()) {
         if (!$listingProduct->getMagentoProduct()->isStockAvailability()) {
             return true;
         } else {
             if ($ebayListingProduct->isVariationsReady()) {
                 $temp = $variationResource->isAllDoNotHaveStockAvailabilities($listingProduct->getId(), $listingProduct->getListing()->getStoreId());
                 if (!is_null($temp) && $temp) {
                     return true;
                 }
             }
         }
     }
     if ($ebaySynchronizationTemplate->isStopWhenQtyMagentoHasValue()) {
         $productQty = (int) $listingProduct->getMagentoProduct()->getQty(true);
         $typeQty = (int) $ebaySynchronizationTemplate->getStopWhenQtyMagentoHasValueType();
         $minQty = (int) $ebaySynchronizationTemplate->getStopWhenQtyMagentoHasValueMin();
         $maxQty = (int) $ebaySynchronizationTemplate->getStopWhenQtyMagentoHasValueMax();
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::STOP_QTY_LESS && $productQty <= $minQty) {
             return true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::STOP_QTY_MORE && $productQty >= $minQty) {
             return true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::STOP_QTY_BETWEEN && $productQty >= $minQty && $productQty <= $maxQty) {
             return true;
         }
     }
     if ($ebaySynchronizationTemplate->isStopWhenQtyCalculatedHasValue()) {
         $productQty = (int) $ebayListingProduct->getQty();
         $typeQty = (int) $ebaySynchronizationTemplate->getStopWhenQtyCalculatedHasValueType();
         $minQty = (int) $ebaySynchronizationTemplate->getStopWhenQtyCalculatedHasValueMin();
         $maxQty = (int) $ebaySynchronizationTemplate->getStopWhenQtyCalculatedHasValueMax();
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::STOP_QTY_LESS && $productQty <= $minQty) {
             return true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::STOP_QTY_MORE && $productQty >= $minQty) {
             return true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::STOP_QTY_BETWEEN && $productQty >= $minQty && $productQty <= $maxQty) {
             return true;
         }
     }
     return false;
 }