예제 #1
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @return bool
  * @throws \Ess\M2ePro\Model\Exception
  * @throws \Ess\M2ePro\Model\Exception\Logic
  * @throws \Exception
  */
 public function isMeetListRequirements(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     if (!$listingProduct->isNotListed() || $listingProduct->isBlocked()) {
         return false;
     }
     if (!$listingProduct->isListable()) {
         return false;
     }
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product $amazonListingProduct */
     $amazonListingProduct = $listingProduct->getChildObject();
     $variationManager = $amazonListingProduct->getVariationManager();
     $searchGeneralId = $amazonListingProduct->getListingSource()->getSearchGeneralId();
     $searchWorldwideId = $amazonListingProduct->getListingSource()->getSearchWorldwideId();
     if ($variationManager->isVariationProduct()) {
         if ($variationManager->isPhysicalUnit() && !$variationManager->getTypeModel()->isVariationProductMatched()) {
             return false;
         }
         if ($variationManager->isRelationParentType() && $amazonListingProduct->getGeneralId()) {
             return false;
         }
         if ($variationManager->isRelationChildType()) {
             if (!$amazonListingProduct->getGeneralId() && !$amazonListingProduct->isGeneralIdOwner()) {
                 return false;
             }
         }
         if ($variationManager->isIndividualType()) {
             if (!$amazonListingProduct->getGeneralId() && ($listingProduct->getMagentoProduct()->isSimpleTypeWithCustomOptions() || $listingProduct->getMagentoProduct()->isBundleType())) {
                 return false;
             }
         }
         if ($variationManager->isRelationParentType() && empty($searchGeneralId) && !$amazonListingProduct->isGeneralIdOwner()) {
             return false;
         }
     }
     if (!$amazonListingProduct->getGeneralId() && !$amazonListingProduct->isGeneralIdOwner() && empty($searchGeneralId) && empty($searchWorldwideId)) {
         return false;
     }
     $amazonSynchronizationTemplate = $amazonListingProduct->getAmazonSynchronizationTemplate();
     if (!$amazonSynchronizationTemplate->isListMode()) {
         return false;
     }
     if ($listingProduct->isSetProcessingLock('in_action')) {
         return false;
     }
     $variationResource = $this->activeRecordFactory->getObject('Listing\\Product\\Variation')->getResource();
     $additionalData = $listingProduct->getAdditionalData();
     $log = $this->activeRecordFactory->getObject('Log\\AbstractLog');
     if ($amazonSynchronizationTemplate->isListStatusEnabled()) {
         if (!$listingProduct->getMagentoProduct()->isStatusEnabled()) {
             // M2ePro\TRANSLATIONS
             // Product was not automatically Listed according to the List Rules in Synchronization Policy. Status of Magento Product is Disabled (%date%) though in Synchronization Rules “Product Status” is set to Enabled.
             $note = $log->encodeDescription('Product was not automatically Listed according to the List Rules in Synchronization Policy.
                  Status of Magento Product is Disabled (%date%) though in Synchronization Rules “Product Status”
                  is set to Enabled.', array('date' => $this->getHelper('Data')->getCurrentGmtDate()));
             $additionalData['synch_template_list_rules_note'] = $note;
             $listingProduct->setSettings('additional_data', $additionalData)->save();
             return false;
         } else {
             if ($variationManager->isPhysicalUnit() && $variationManager->getTypeModel()->isVariationProductMatched()) {
                 $temp = $variationResource->isAllStatusesDisabled($listingProduct->getId(), $listingProduct->getListing()->getStoreId());
                 if (!is_null($temp) && $temp) {
                     // M2ePro\TRANSLATIONS
                     // Product was not automatically Listed according to the List Rules in Synchronization Policy. Status of Magento Product Variation is Disabled (%date%) though in Synchronization Rules “Product Status“ is set to Enabled.
                     $note = $log->encodeDescription('Product was not automatically Listed according to the List Rules in Synchronization Policy.
                      Status of Magento Product Variation is Disabled (%date%) though in Synchronization Rules
                      “Product Status“ is set to Enabled.', array('date' => $this->getHelper('Data')->getCurrentGmtDate()));
                     $additionalData['synch_template_list_rules_note'] = $note;
                     $listingProduct->setSettings('additional_data', $additionalData)->save();
                     return false;
                 }
             }
         }
     }
     if ($amazonSynchronizationTemplate->isListIsInStock()) {
         if (!$listingProduct->getMagentoProduct()->isStockAvailability()) {
             // M2ePro\TRANSLATIONS
             // Product was not automatically Listed according to the List Rules in Synchronization Policy. Stock Availability of Magento Product is Out of Stock though in Synchronization Rules “Stock Availability” is set to In Stock.
             $note = $log->encodeDescription('Product was not automatically Listed according to the List Rules in Synchronization Policy.
                  Stock Availability of Magento Product is Out of Stock though in
                  Synchronization Rules “Stock Availability” is set to In Stock.', array('date' => $this->getHelper('Data')->getCurrentGmtDate()));
             $additionalData['synch_template_list_rules_note'] = $note;
             $listingProduct->setSettings('additional_data', $additionalData)->save();
             return false;
         } else {
             if ($variationManager->isPhysicalUnit() && $variationManager->getTypeModel()->isVariationProductMatched()) {
                 $temp = $variationResource->isAllDoNotHaveStockAvailabilities($listingProduct->getId(), $listingProduct->getListing()->getStoreId());
                 if (!is_null($temp) && $temp) {
                     // M2ePro\TRANSLATIONS
                     // Product was not automatically Listed according to the List Rules in Synchronization Policy. Stock Availability of Magento Product Variation is Out of Stock though in Synchronization Rules “Stock Availability” is set to In Stock.
                     $note = $log->encodeDescription('Product was not automatically Listed according to the List Rules in Synchronization Policy.
                      Stock Availability of Magento Product Variation is Out of Stock though
                      in Synchronization Rules “Stock Availability” is set to In Stock.', array('date' => $this->getHelper('Data')->getCurrentGmtDate()));
                     $additionalData['synch_template_list_rules_note'] = $note;
                     $listingProduct->setSettings('additional_data', $additionalData)->save();
                     return false;
                 }
             }
         }
     }
     if ($amazonSynchronizationTemplate->isListWhenQtyMagentoHasValue()) {
         $result = false;
         if ($variationManager->isRelationParentType()) {
             $productQty = (int) $listingProduct->getMagentoProduct()->getQty(true);
         } else {
             $productQty = (int) $amazonListingProduct->getQty(true);
         }
         $typeQty = (int) $amazonSynchronizationTemplate->getListWhenQtyMagentoHasValueType();
         $minQty = (int) $amazonSynchronizationTemplate->getListWhenQtyMagentoHasValueMin();
         $maxQty = (int) $amazonSynchronizationTemplate->getListWhenQtyMagentoHasValueMax();
         $note = '';
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::LIST_QTY_LESS) {
             if ($productQty <= $minQty) {
                 $result = true;
             } else {
                 // M2ePro\TRANSLATIONS
                 // Product was not automatically Listed according to the List Rules in Synchronization Policy. Quantity of Magento Product is %product_qty% though in Synchronization Rules “Magento Quantity“ is set to less then  %template_min_qty%.
                 $note = $log->encodeDescription('Product was not automatically Listed according to the List Rules in Synchronization Policy.
                      Quantity of Magento Product is %product_qty% though in Synchronization Rules
                      “Magento Quantity“ is set to less then  %template_min_qty%.', array('!template_min_qty' => $minQty, '!product_qty' => $productQty, '!date' => $this->getHelper('Data')->getCurrentGmtDate()));
             }
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::LIST_QTY_MORE) {
             if ($productQty >= $minQty) {
                 $result = true;
             } else {
                 // M2ePro\TRANSLATIONS
                 // Product was not automatically Listed according to the List Rules in Synchronization Policy. Quantity of Magento Product is %product_qty% though in Synchronization Rules “Magento Quantity” is set to more then  %template_min_qty%.
                 $note = $log->encodeDescription('Product was not automatically Listed according to the List Rules in Synchronization Policy.
                      Quantity of Magento Product is %product_qty% though in Synchronization Rules
                      “Magento Quantity” is set to more then  %template_min_qty%.', array('!template_min_qty' => $minQty, '!product_qty' => $productQty, '!date' => $this->getHelper('Data')->getCurrentGmtDate()));
             }
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::LIST_QTY_BETWEEN) {
             if ($productQty >= $minQty && $productQty <= $maxQty) {
                 $result = true;
             } else {
                 // M2ePro\TRANSLATIONS
                 // Product was not automatically Listed according to the List Rules in Synchronization Policy. Quantity of Magento Product is %product_qty% though in Synchronization Rules “Magento Quantity” is set between  %template_min_qty% and %template_max_qty%.
                 $note = $log->encodeDescription('Product was not automatically Listed according to the List Rules in Synchronization Policy.
                      Quantity of Magento Product is %product_qty% though in Synchronization Rules
                      “Magento Quantity” is set between  %template_min_qty% and %template_max_qty%.', array('!template_min_qty' => $minQty, '!template_max_qty' => $maxQty, '!product_qty' => $productQty, '!date' => $this->getHelper('Data')->getCurrentGmtDate()));
             }
         }
         if (!$result) {
             if (!empty($note)) {
                 $additionalData['synch_template_list_rules_note'] = $note;
                 $listingProduct->setSettings('additional_data', $additionalData)->save();
             }
             return false;
         }
     }
     if ($amazonSynchronizationTemplate->isListWhenQtyCalculatedHasValue() && !$variationManager->isRelationParentType()) {
         $result = false;
         $productQty = (int) $amazonListingProduct->getQty(false);
         $typeQty = (int) $amazonSynchronizationTemplate->getListWhenQtyCalculatedHasValueType();
         $minQty = (int) $amazonSynchronizationTemplate->getListWhenQtyCalculatedHasValueMin();
         $maxQty = (int) $amazonSynchronizationTemplate->getListWhenQtyCalculatedHasValueMax();
         $note = '';
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::LIST_QTY_LESS) {
             if ($productQty <= $minQty) {
                 $result = true;
             } else {
                 // M2ePro\TRANSLATIONS
                 // Product was not automatically Listed according to the List Rules in Synchronization Policy. Quantity of Magento Product is %product_qty% though in Synchronization Rules “Calculated Quantity” is set to less then %template_min_qty%.
                 $note = $log->encodeDescription('Product was not automatically Listed according to the List Rules in Synchronization Policy.
                      Quantity of Magento Product is %product_qty% though in Synchronization Rules
                      “Calculated Quantity” is set to less then %template_min_qty%.', array('!template_min_qty' => $minQty, '!product_qty' => $productQty, '!date' => $this->getHelper('Data')->getCurrentGmtDate()));
             }
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::LIST_QTY_MORE) {
             if ($productQty >= $minQty) {
                 $result = true;
             } else {
                 // M2ePro\TRANSLATIONS
                 // Product was not automatically Listed according to the List Rules in Synchronization Policy. Quantity of Magento Product is %product_qty% though in Synchronization Rules “Calculated Quantity” is set to more then  %template_min_qty%.
                 $note = $log->encodeDescription('Product was not automatically Listed according to the List Rules in Synchronization Policy.
                      Quantity of Magento Product is %product_qty% though in Synchronization Rules
                      “Calculated Quantity” is set to more then  %template_min_qty%.', array('!template_min_qty' => $minQty, '!product_qty' => $productQty, '!date' => $this->getHelper('Data')->getCurrentGmtDate()));
             }
         }
         if ($typeQty == \Ess\M2ePro\Model\Amazon\Template\Synchronization::LIST_QTY_BETWEEN) {
             if ($productQty >= $minQty && $productQty <= $maxQty) {
                 $result = true;
             } else {
                 // M2ePro\TRANSLATIONS
                 // Product was not automatically Listed according to the List Rules in Synchronization Policy. Quantity of Magento Product is %product_qty% though in Synchronization Rules “Calculated Quantity” is set between  %template_min_qty% and %template_max_qty%.
                 $note = $log->encodeDescription('Product was not automatically Listed according to the List Rules in Synchronization Policy.
                      Quantity of Magento Product is %product_qty% though in Synchronization Rules
                      “Calculated Quantity” is set between  %template_min_qty% and %template_max_qty%.', array('!template_min_qty' => $minQty, '!template_max_qty' => $maxQty, '!product_qty' => $productQty, '!date' => $this->getHelper('Data')->getCurrentGmtDate()));
             }
         }
         if (!$result) {
             if (!empty($note)) {
                 $additionalData['synch_template_list_rules_note'] = $note;
                 $listingProduct->setSettings('additional_data', $additionalData)->save();
             }
             return false;
         }
     }
     if ($listingProduct->getSynchStatus() != \Ess\M2ePro\Model\Listing\Product::SYNCH_STATUS_NEED && $this->isTriedToList($listingProduct) && $this->isChangeInitiatorOnlyInspector($listingProduct)) {
         return false;
     }
     return true;
 }