private function duplicateListingProduct(\Ess\M2ePro\Model\Listing\Product $listingProduct) { $duplicatedListingProduct = $listingProduct->getListing()->addProduct($listingProduct->getProductId(), false, false); $variationManager = $listingProduct->getChildObject()->getVariationManager(); if (!$variationManager->isVariationProduct()) { return $duplicatedListingProduct; } if ($listingProduct->isComponentModeAmazon()) { $duplicatedListingProductManager = $duplicatedListingProduct->getChildObject()->getVariationManager(); if ($variationManager->isIndividualType() && $duplicatedListingProductManager->modeCanBeSwitched()) { $duplicatedListingProductManager->switchModeToAnother(); } } return $duplicatedListingProduct; }
/** * @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 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(); }
/** * @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; }