Example #1
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @return bool
  * @throws \Ess\M2ePro\Model\Exception\Logic
  */
 public function isMeetRelistRequirements(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     if ($listingProduct->isListed()) {
         return false;
     }
     if (!$listingProduct->isRelistable() && !$listingProduct->isHidden()) {
         return false;
     }
     /** @var \Ess\M2ePro\Model\Ebay\Listing\Product $ebayListingProduct */
     $ebayListingProduct = $listingProduct->getChildObject();
     $ebaySynchronizationTemplate = $ebayListingProduct->getEbaySynchronizationTemplate();
     // Correct synchronization
     // ---------------------------------------
     if (!$ebaySynchronizationTemplate->isRelistMode()) {
         return false;
     }
     if ($listingProduct->isStopped() && $ebaySynchronizationTemplate->isRelistFilterUserLock() && $listingProduct->getStatusChanger() == \Ess\M2ePro\Model\Listing\Product::STATUS_CHANGER_USER) {
         return false;
     }
     if (!$ebayListingProduct->isSetCategoryTemplate()) {
         return false;
     }
     // ---------------------------------------
     if ($listingProduct->isSetProcessingLock('in_action')) {
         return false;
     }
     $variationResource = $this->activeRecordFactory->getObject('Listing\\Product\\Variation')->getResource();
     // Check filters
     // ---------------------------------------
     if ($ebaySynchronizationTemplate->isRelistStatusEnabled()) {
         if (!$listingProduct->getMagentoProduct()->isStatusEnabled()) {
             return false;
         } else {
             if ($ebayListingProduct->isVariationsReady()) {
                 $temp = $variationResource->isAllStatusesDisabled($listingProduct->getId(), $listingProduct->getListing()->getStoreId());
                 if (!is_null($temp) && $temp) {
                     return false;
                 }
             }
         }
     }
     if ($ebaySynchronizationTemplate->isRelistIsInStock()) {
         if (!$listingProduct->getMagentoProduct()->isStockAvailability()) {
             return false;
         } else {
             if ($ebayListingProduct->isVariationsReady()) {
                 $temp = $variationResource->isAllDoNotHaveStockAvailabilities($listingProduct->getId(), $listingProduct->getListing()->getStoreId());
                 if (!is_null($temp) && $temp) {
                     return false;
                 }
             }
         }
     }
     if ($ebaySynchronizationTemplate->isRelistWhenQtyMagentoHasValue()) {
         $result = false;
         $productQty = (int) $listingProduct->getMagentoProduct()->getQty(true);
         $typeQty = (int) $ebaySynchronizationTemplate->getRelistWhenQtyMagentoHasValueType();
         $minQty = (int) $ebaySynchronizationTemplate->getRelistWhenQtyMagentoHasValueMin();
         $maxQty = (int) $ebaySynchronizationTemplate->getRelistWhenQtyMagentoHasValueMax();
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::RELIST_QTY_LESS && $productQty <= $minQty) {
             $result = true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::RELIST_QTY_MORE && $productQty >= $minQty) {
             $result = true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::RELIST_QTY_BETWEEN && $productQty >= $minQty && $productQty <= $maxQty) {
             $result = true;
         }
         if (!$result) {
             return false;
         }
     }
     if ($ebaySynchronizationTemplate->isRelistWhenQtyCalculatedHasValue()) {
         $result = false;
         $productQty = (int) $ebayListingProduct->getQty();
         $typeQty = (int) $ebaySynchronizationTemplate->getRelistWhenQtyCalculatedHasValueType();
         $minQty = (int) $ebaySynchronizationTemplate->getRelistWhenQtyCalculatedHasValueMin();
         $maxQty = (int) $ebaySynchronizationTemplate->getRelistWhenQtyCalculatedHasValueMax();
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::RELIST_QTY_LESS && $productQty <= $minQty) {
             $result = true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::RELIST_QTY_MORE && $productQty >= $minQty) {
             $result = true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Ebay\Template\Synchronization::RELIST_QTY_BETWEEN && $productQty >= $minQty && $productQty <= $maxQty) {
             $result = true;
         }
         if (!$result) {
             return false;
         }
     }
     // ---------------------------------------
     return true;
 }
Example #2
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @return bool
  * @throws \Ess\M2ePro\Model\Exception
  * @throws \Ess\M2ePro\Model\Exception\Logic
  */
 public function isMeetRelistRequirements(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     if (!$listingProduct->isStopped() || $listingProduct->isBlocked()) {
         return false;
     }
     if (!$listingProduct->isRelistable()) {
         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 (!$variationManager->getTypeModel()->isVariationProductMatched()) {
             return false;
         }
     }
     $amazonSynchronizationTemplate = $amazonListingProduct->getAmazonSynchronizationTemplate();
     if (!$amazonSynchronizationTemplate->isRelistMode()) {
         return false;
     }
     if ($amazonSynchronizationTemplate->isRelistFilterUserLock() && $listingProduct->getStatusChanger() == \Ess\M2ePro\Model\Listing\Product::STATUS_CHANGER_USER) {
         return false;
     }
     if ($listingProduct->isSetProcessingLock('in_action')) {
         return false;
     }
     $variationResource = $this->activeRecordFactory->getObject('Listing\\Product\\Variation')->getResource();
     if ($amazonSynchronizationTemplate->isRelistStatusEnabled()) {
         if (!$listingProduct->getMagentoProduct()->isStatusEnabled()) {
             return false;
         } else {
             if ($variationManager->isPhysicalUnit() && $variationManager->getTypeModel()->isVariationProductMatched()) {
                 $temp = $variationResource->isAllStatusesDisabled($listingProduct->getId(), $listingProduct->getListing()->getStoreId());
                 if (!is_null($temp) && $temp) {
                     return false;
                 }
             }
         }
     }
     if ($amazonSynchronizationTemplate->isRelistIsInStock()) {
         if (!$listingProduct->getMagentoProduct()->isStockAvailability()) {
             return false;
         } else {
             if ($variationManager->isPhysicalUnit() && $variationManager->getTypeModel()->isVariationProductMatched()) {
                 $temp = $variationResource->isAllDoNotHaveStockAvailabilities($listingProduct->getId(), $listingProduct->getListing()->getStoreId());
                 if (!is_null($temp) && $temp) {
                     return false;
                 }
             }
         }
     }
     if ($amazonSynchronizationTemplate->isRelistWhenQtyMagentoHasValue()) {
         $result = false;
         $productQty = (int) $amazonListingProduct->getQty(true);
         $typeQty = (int) $amazonSynchronizationTemplate->getRelistWhenQtyMagentoHasValueType();
         $minQty = (int) $amazonSynchronizationTemplate->getRelistWhenQtyMagentoHasValueMin();
         $maxQty = (int) $amazonSynchronizationTemplate->getRelistWhenQtyMagentoHasValueMax();
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::RELIST_QTY_LESS && $productQty <= $minQty) {
             $result = true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::RELIST_QTY_MORE && $productQty >= $minQty) {
             $result = true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::RELIST_QTY_BETWEEN && $productQty >= $minQty && $productQty <= $maxQty) {
             $result = true;
         }
         if (!$result) {
             return false;
         }
     }
     if ($amazonSynchronizationTemplate->isRelistWhenQtyCalculatedHasValue()) {
         $result = false;
         $productQty = (int) $amazonListingProduct->getQty(false);
         $typeQty = (int) $amazonSynchronizationTemplate->getRelistWhenQtyCalculatedHasValueType();
         $minQty = (int) $amazonSynchronizationTemplate->getRelistWhenQtyCalculatedHasValueMin();
         $maxQty = (int) $amazonSynchronizationTemplate->getRelistWhenQtyCalculatedHasValueMax();
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::RELIST_QTY_LESS && $productQty <= $minQty) {
             $result = true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::RELIST_QTY_MORE && $productQty >= $minQty) {
             $result = true;
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::RELIST_QTY_BETWEEN && $productQty >= $minQty && $productQty <= $maxQty) {
             $result = true;
         }
         if (!$result) {
             return false;
         }
     }
     return true;
 }
Example #3
0
 protected function inspectProduct()
 {
     if (!$this->isSuccess && !$this->isSkipped) {
         return;
     }
     /** @var Runner $runner */
     $runner = $this->modelFactory->getObject('Synchronization\\Templates\\Synchronization\\Runner');
     $runner->setConnectorModel('Ebay\\Connector\\Item\\Dispatcher');
     $runner->setMaxProductsPerStep(100);
     /** @var Inspector $inspector */
     $inspector = $this->modelFactory->getObject('Ebay\\Synchronization\\Templates\\Synchronization\\Inspector');
     /** @var \Ess\M2ePro\Model\Ebay\Listing\Product $ebayListingProduct */
     $ebayListingProduct = $this->listingProduct->getChildObject();
     if ($this->listingProduct->isListed()) {
         /** @var Configurator $configurator */
         $configurator = $this->modelFactory->getObject('Ebay\\Listing\\Product\\Action\\Configurator');
         if ($inspector->isMeetStopRequirements($this->listingProduct)) {
             $action = \Ess\M2ePro\Model\Listing\Product::ACTION_STOP;
             if ($ebayListingProduct->isOutOfStockControlEnabled()) {
                 $action = \Ess\M2ePro\Model\Listing\Product::ACTION_REVISE;
                 $configurator->setParams(array('replaced_action' => \Ess\M2ePro\Model\Listing\Product::ACTION_STOP));
                 $configurator->setPartialMode();
                 $configurator->allowQty()->allowVariations();
             }
             $runner->addProduct($this->listingProduct, $action, $configurator);
             $runner->execute();
             return;
         }
         $configurator->setPartialMode();
         $needRevise = false;
         if ($inspector->isMeetReviseQtyRequirements($this->listingProduct)) {
             $configurator->allowQty();
             $needRevise = true;
         }
         if ($inspector->isMeetRevisePriceRequirements($this->listingProduct)) {
             $configurator->allowPrice();
             $needRevise = true;
         }
         if (!$needRevise) {
             return;
         }
         if ($ebayListingProduct->isVariationsReady()) {
             $configurator->allowVariations();
         }
         $runner->addProduct($this->listingProduct, \Ess\M2ePro\Model\Listing\Product::ACTION_REVISE, $configurator);
         $runner->execute();
         return;
     }
     if ($this->listingProduct->isStopped() || $this->listingProduct->isHidden()) {
         if (!$inspector->isMeetRelistRequirements($this->listingProduct)) {
             return;
         }
         /** @var Configurator $configurator */
         $configurator = $this->modelFactory->getObject('Ebay\\Listing\\Product\\Action\\Configurator');
         $action = \Ess\M2ePro\Model\Listing\Product::ACTION_RELIST;
         if ($this->listingProduct->isHidden()) {
             $configurator->setParams(array('replaced_action' => \Ess\M2ePro\Model\Listing\Product::ACTION_RELIST));
             $action = \Ess\M2ePro\Model\Listing\Product::ACTION_REVISE;
         }
         if (!$ebayListingProduct->getEbaySynchronizationTemplate()->isRelistSendData()) {
             $configurator->setPartialMode();
             $configurator->allowQty()->allowPrice()->allowVariations();
         }
         $runner->addProduct($this->listingProduct, $action, $configurator);
         $runner->execute();
     }
 }