protected function validateChannelConditions($sourceVariations, $writeLogs = true) { $tempLog = Mage::getModel('M2ePro/Listing_Log'); $tempLog->setComponentMode(Ess_M2ePro_Helper_Component_Ebay::NICK); $failResult = array('set' => array(), 'variations' => array()); $set = $sourceVariations['set']; $variations = $sourceVariations['variations']; foreach ($set as $singleSet) { if (count($singleSet) > 30) { // Maximum 30 options by one attribute: // Color: Red, Blue, Green, ... $writeLogs && $tempLog->addProductMessage($this->listingProduct->getListingId(), $this->listingProduct->getProductId(), $this->listingProduct->getId(), $this->logsInitiator, $this->logsActionId, $this->logsAction, 'The product will be listed as a simple product as it has limitation for multi-variation items. Reason: ' . 'number of values for each option more than 30.', Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING, Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM); return $failResult; } } foreach ($variations as $singleVariation) { if (count($singleVariation) > 5) { // Max 5 pair attribute-option: // Color: Blue, Size: XL, ... $writeLogs && $tempLog->addProductMessage($this->listingProduct->getListingId(), $this->listingProduct->getProductId(), $this->listingProduct->getId(), Ess_M2ePro_Model_Log_Abstract::INITIATOR_UNKNOWN, NULL, Ess_M2ePro_Model_Listing_Log::ACTION_ADD_PRODUCT_TO_LISTING, 'The product will be listed as a simple product as it has limitation for multi-variation items. Reason: ' . 'number of options more than 5.', Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING, Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM); return $failResult; } } if (count($variations) > 250) { // Not more that 250 possible variations $writeLogs && $tempLog->addProductMessage($this->listingProduct->getListingId(), $this->listingProduct->getProductId(), $this->listingProduct->getId(), Ess_M2ePro_Model_Log_Abstract::INITIATOR_UNKNOWN, NULL, Ess_M2ePro_Model_Listing_Log::ACTION_ADD_PRODUCT_TO_LISTING, 'The product will be listed as a simple product as it has limitation for multi-variation items. Reason: ' . 'sum of quantities of all possible products options more than 250.', Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING, Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM); return $failResult; } return $sourceVariations; }
private function checkVariationStructureChanges(Ess_M2ePro_Model_Listing_Product $listingProduct) { /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager $variationManager */ $variationManager = $listingProduct->getChildObject()->getVariationManager(); /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Abstract $typeModel */ $typeModel = $variationManager->getTypeModel(); if ($variationManager->isRelationParentType()) { $this->parentListingsProductsForProcessing[$listingProduct->getId()] = $listingProduct; return; } /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_PhysicalUnit $typeModel */ if (!$typeModel->isActualProductAttributes()) { if ($variationManager->isRelationChildType()) { /** @var Ess_M2ePro_Model_Amazon_Listing_Product_Variation_Manager_Type_Relation_Child $typeModel */ $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_Child $typeModel */ $this->parentListingsProductsForProcessing[$typeModel->getParentListingProduct()->getId()] = $typeModel->getParentListingProduct(); return; } $typeModel->unsetProductVariation(); } }
public function isExistProductAction(Ess_M2ePro_Model_Listing_Product $listingProductInstance, $action, array $params = array()) { $newListingsProductId = $listingProductInstance->getId(); $params['status_changer'] = Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_SYNCH; if (!isset($this->_actionsProducts[$newListingsProductId])) { return false; } if ($this->_actionsProducts[$newListingsProductId]['action'] != $action) { return false; } $tempExistItem = $this->_actionsProducts[$newListingsProductId]; foreach ($params as $tempParamKey => $tempParamValue) { if (!isset($tempExistItem['params'][$tempParamKey])) { return false; } if (is_array($tempExistItem['params'][$tempParamKey]) && is_array($tempParamValue)) { foreach ($tempParamValue as $tempParamKeyTwo => $tempParamValueTwo) { if (!isset($tempExistItem['params'][$tempParamKey][$tempParamKeyTwo])) { return false; } if ($tempExistItem['params'][$tempParamKey][$tempParamKeyTwo] != $tempParamValueTwo) { return false; } } continue; } if ($tempExistItem['params'][$tempParamKey] != $tempParamValue) { return false; } } return true; }
public function logListingProductMessage(Ess_M2ePro_Model_Listing_Product $listingProduct, array $messageData, $priority = Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM) { if ($this->storeMode) { $this->storedMessages[] = array('type' => $this->initLogType($messageData[Ess_M2ePro_Model_Connector_Protocol::MESSAGE_TYPE_KEY]), 'text' => $messageData[Ess_M2ePro_Model_Connector_Protocol::MESSAGE_TEXT_KEY]); return; } $this->getListingLog()->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), $this->initiator, $this->actionId, $this->action, $messageData[Ess_M2ePro_Model_Connector_Protocol::MESSAGE_TEXT_KEY], $this->initLogType($messageData[Ess_M2ePro_Model_Connector_Protocol::MESSAGE_TYPE_KEY]), $priority); }
protected function getSuccessfulParams(Ess_M2ePro_Model_Listing_Product $listingProduct, $response) { foreach ($response['skus'] as $key => $generalId) { if ((int) $key != (int) $listingProduct->getId()) { continue; } return array('general_id' => $generalId); } return array(); }
protected function getSuccessfulParams(Ess_M2ePro_Model_Listing_Product $listingProduct, $response) { if (!is_array($response['asins']) || empty($response['asins'])) { return array(); } foreach ($response['asins'] as $key => $asin) { if ((int) $key != (int) $listingProduct->getId()) { continue; } return array('general_id' => $asin); } return array(); }
public function process(Ess_M2ePro_Model_Listing_Product $listingProduct, $query) { $searchMethod = 'byQuery'; $tempQuery = str_replace('-', '', $query); if ($this->isQueryEan($tempQuery) || $this->isQueryIsbn($tempQuery)) { $query = $tempQuery; $searchMethod = 'byEanIsbn'; } $params = array('query' => $query, 'type' => 'manual', 'listing_product_id' => $listingProduct->getId()); Mage::getModel('M2ePro/Connector_Play_Dispatcher')->processConnector('search', $searchMethod, 'requester', $params, $listingProduct->getAccount(), 'Ess_M2ePro_Model_Play'); $result = Mage::helper('M2ePro/Data_Global')->getValue('temp_play_manual_search_result'); Mage::helper('M2ePro/Data_Global')->unsetValue('temp_play_manual_search_result'); return $result; }
public function process(Ess_M2ePro_Model_Listing_Product $listingProduct, $query) { $searchMethod = 'byQuery'; if ($this->isQueryGeneralId($query) || $this->isQueryUpc($query)) { $searchMethod = 'byIdentifier'; } $params = array('query' => $query, 'type' => 'manual', 'listing_product_id' => $listingProduct->getId()); if ($searchMethod == 'byIdentifier') { $params['search_type'] = $this->getSearchType($query); } Mage::getModel('M2ePro/Connector_Buy_Dispatcher')->processConnector('search', $searchMethod, 'requester', $params, $listingProduct->getAccount(), 'Ess_M2ePro_Model_Buy'); $result = Mage::helper('M2ePro/Data_Global')->getValue('temp_buy_manual_search_result'); Mage::helper('M2ePro/Data_Global')->unsetValue('temp_buy_manual_search_result'); return $result; }
protected function addListingsProductsLogsMessage(Ess_M2ePro_Model_Listing_Product $listingProduct, $text, $type = Ess_M2ePro_Model_Log_Abstract::TYPE_NOTICE, $priority = Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM) { $action = Ess_M2ePro_Model_Listing_Log::ACTION_TRANSLATE_PRODUCT; if ($this->getStatusChanger() == Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_UNKNOWN) { $initiator = Ess_M2ePro_Helper_Data::INITIATOR_UNKNOWN; } else { if ($this->getStatusChanger() == Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_USER) { $initiator = Ess_M2ePro_Helper_Data::INITIATOR_USER; } else { $initiator = Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION; } } $logModel = Mage::getModel('M2ePro/Listing_Log'); $logModel->setComponentMode(Ess_M2ePro_Helper_Component_Ebay::NICK); $logModel->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), $initiator, $this->getLogsActionId(), $action, $text, $type, $priority); }
public function process(Ess_M2ePro_Model_Listing_Product $listingProduct, $query) { $searchMethod = 'byQuery'; $validation = Mage::helper('M2ePro'); $tempQuery = str_replace('-', '', $query); if (Mage::helper('M2ePro/Component_Amazon')->isASIN($tempQuery) || $validation->isISBN10($tempQuery)) { $query = $tempQuery; $searchMethod = 'byAsin'; } elseif ($validation->isEAN($tempQuery) || $validation->isUPC($tempQuery) || $validation->isISBN13($tempQuery)) { $query = $tempQuery; $searchMethod = 'byIdentifier'; } $params = array('item' => $query, 'type' => 'manual', 'only_realtime' => true, 'search_method' => $searchMethod, 'listing_product_id' => $listingProduct->getId()); if ($searchMethod == 'byIdentifier') { $params['id_type'] = $this->getIdentifierType($query); } Mage::getModel('M2ePro/Connector_Amazon_Dispatcher')->processConnector('search', $searchMethod, 'requester', $params, $listingProduct->getAccount(), 'Ess_M2ePro_Model_Amazon'); $result = Mage::helper('M2ePro/Data_Global')->getValue('temp_amazon_manual_search_result'); Mage::helper('M2ePro/Data_Global')->unsetValue('temp_amazon_manual_search_result'); return $result; }
private function modifyAndLogListingProduct(Ess_M2ePro_Model_Listing_Product $listingProduct, $status, $duplicateItemId = null) { /** @var Ess_M2ePro_Model_Listing_Log $logModel */ $logModel = Mage::getModel('M2ePro/Listing_Log'); $logModel->setComponentMode(Ess_M2ePro_Helper_Component_Ebay::NICK); $logsActionId = $logModel->getNextActionId(); $statusLogMessage = $this->getStatusLogMessage($listingProduct->getStatus(), $status); $logModel->addProductMessage($listingProduct->getData('listing_id'), $listingProduct->getData('product_id'), $listingProduct->getId(), Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION, $logsActionId, Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE, $statusLogMessage, Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS, Ess_M2ePro_Model_Log_Abstract::PRIORITY_LOW); $additionalData = $listingProduct->getAdditionalData(); unset($additionalData['last_failed_action_data']); $listingProduct->addData(array('status' => $status, 'additional_data' => json_encode($additionalData)))->save(); $listingProduct->getChildObject()->updateVariationsStatus(); if (is_null($duplicateItemId)) { return; } // M2ePro_TRANSLATIONS // Duplicated Item %item_id% was found and Stopped on eBay. $textToTranslate = 'Duplicated Item %item_id% was found and stopped on eBay.'; $duplicateDeletedMessage = Mage::helper('M2ePro')->__($textToTranslate, $duplicateItemId); $logModel->addProductMessage($listingProduct->getData('listing_id'), $listingProduct->getData('product_id'), $listingProduct->getId(), Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION, $logsActionId, Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE, $duplicateDeletedMessage, Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING, Ess_M2ePro_Model_Log_Abstract::PRIORITY_LOW); }
protected function addBaseListingsLogsMessage(Ess_M2ePro_Model_Listing_Product $listingProduct, $text, $type = Ess_M2ePro_Model_Log_Abstract::TYPE_NOTICE, $priority = Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM, $isListingMode = true) { $action = $this->getListingsLogsCurrentAction(); is_null($action) && ($action = Ess_M2ePro_Model_Listing_Log::ACTION_UNKNOWN); switch ($type) { case Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR: $this->setStatus(Ess_M2ePro_Helper_Data::STATUS_ERROR); break; case Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING: $this->setStatus(Ess_M2ePro_Helper_Data::STATUS_WARNING); break; case Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS: case Ess_M2ePro_Model_Log_Abstract::TYPE_NOTICE: $this->setStatus(Ess_M2ePro_Helper_Data::STATUS_SUCCESS); break; default: $this->setStatus(Ess_M2ePro_Helper_Data::STATUS_ERROR); break; } $initiator = Ess_M2ePro_Model_Log_Abstract::INITIATOR_UNKNOWN; if ($this->params['status_changer'] == Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_UNKNOWN) { $initiator = Ess_M2ePro_Model_Log_Abstract::INITIATOR_UNKNOWN; } else { if ($this->params['status_changer'] == Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_USER) { $initiator = Ess_M2ePro_Model_Log_Abstract::INITIATOR_USER; } else { $initiator = Ess_M2ePro_Model_Log_Abstract::INITIATOR_EXTENSION; } } $logModel = Mage::getModel('M2ePro/Listing_Log'); $logModel->setComponentMode(Ess_M2ePro_Helper_Component_Play::NICK); if ($isListingMode) { $logModel->addListingMessage($listingProduct->getListingId(), $initiator, $this->logsActionId, $action, $text, $type, $priority); } else { $logModel->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), $initiator, $this->logsActionId, $action, $text, $type, $priority); } }
/** * @param Ess_M2ePro_Model_Listing_Product $listingProduct * @return Ess_M2ePro_Model_Buy_Listing_Product_Action_RequestData */ protected function getRequestDataObject(Ess_M2ePro_Model_Listing_Product $listingProduct) { if (!isset($this->requestsDataObjects[$listingProduct->getId()])) { /** @var Ess_M2ePro_Model_Buy_Listing_Product_Action_RequestData $requestData */ $requestData = Mage::getModel('M2ePro/Buy_Listing_Product_Action_RequestData'); $requestData->setData($this->params['products'][$listingProduct->getId()]); $requestData->setListingProduct($listingProduct); $this->requestsDataObjects[$listingProduct->getId()] = $requestData; } return $this->requestsDataObjects[$listingProduct->getId()]; }
private function isMeetListRequirements(Ess_M2ePro_Model_Listing_Product $listingProduct) { // Is checked before? //-------------------- if (in_array($listingProduct->getId(), $this->_checkedListingsProductsIds)) { return false; } else { $this->_checkedListingsProductsIds[] = $listingProduct->getId(); } //-------------------- // eBay available status //-------------------- if (!$listingProduct->isNotListed()) { return false; } if (!$listingProduct->isListable()) { return false; } if ($this->_runnerActions->isExistProductAction($listingProduct, Ess_M2ePro_Model_Connector_Server_Ebay_Item_Dispatcher::ACTION_LIST, array())) { return false; } //-------------------- /* @var $ebaySynchronizationTemplate Ess_M2ePro_Model_Ebay_Template_Synchronization */ $ebaySynchronizationTemplate = $listingProduct->getChildObject()->getEbaySynchronizationTemplate(); // Correct synchronization //-------------------- if (!$listingProduct->getChildObject()->isSetCategoryTemplate()) { return false; } if (!$ebaySynchronizationTemplate->isListMode()) { return false; } if ($ebaySynchronizationTemplate->isScheduleEnabled()) { if (!$ebaySynchronizationTemplate->isScheduleIntervalNow() || !$ebaySynchronizationTemplate->isScheduleWeekNow()) { return false; } } //-------------------- $productsIdsForEachVariation = NULL; // Check filters //-------------------- if ($ebaySynchronizationTemplate->isListStatusEnabled()) { if ($listingProduct->getMagentoProduct()->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) { return false; } else { if (is_null($productsIdsForEachVariation)) { $productsIdsForEachVariation = $listingProduct->getProductsIdsForEachVariation(); } if (count($productsIdsForEachVariation) > 0) { $tempStatuses = $listingProduct->getVariationsStatuses($productsIdsForEachVariation); // all variations are disabled if ((int) min($tempStatuses) == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) { return false; } } } } if ($ebaySynchronizationTemplate->isListIsInStock()) { if (!$listingProduct->getMagentoProduct()->getStockAvailability()) { return false; } else { if (is_null($productsIdsForEachVariation)) { $productsIdsForEachVariation = $listingProduct->getProductsIdsForEachVariation(); } if (count($productsIdsForEachVariation) > 0) { $tempStocks = $listingProduct->getVariationsStockAvailabilities($productsIdsForEachVariation); // all variations are out of stock if (!(int) max($tempStocks)) { return false; } } } } if ($ebaySynchronizationTemplate->isListWhenQtyHasValue()) { $result = false; $productQty = (int) $listingProduct->getChildObject()->getQty(true); $typeQty = (int) $ebaySynchronizationTemplate->getListWhenQtyHasValueType(); $minQty = (int) $ebaySynchronizationTemplate->getListWhenQtyHasValueMin(); $maxQty = (int) $ebaySynchronizationTemplate->getListWhenQtyHasValueMax(); if ($typeQty == Ess_M2ePro_Model_Ebay_Template_Synchronization::LIST_QTY_LESS && $productQty <= $minQty) { $result = true; } if ($typeQty == Ess_M2ePro_Model_Ebay_Template_Synchronization::LIST_QTY_MORE && $productQty >= $minQty) { $result = true; } if ($typeQty == Ess_M2ePro_Model_Ebay_Template_Synchronization::LIST_QTY_BETWEEN && $productQty >= $minQty && $productQty <= $maxQty) { $result = true; } if (!$result) { return false; } } //-------------------- return true; }
/** * @param Ess_M2ePro_Model_Listing_Product $listingProduct * @return Ess_M2ePro_Model_Buy_Listing_Product_Action_Type_Request */ protected function getRequestObject(Ess_M2ePro_Model_Listing_Product $listingProduct) { if (!isset($this->requestsObjects[$listingProduct->getId()])) { /* @var $request Ess_M2ePro_Model_Buy_Listing_Product_Action_Type_List_Request */ $request = Mage::getModel('M2ePro/Buy_Listing_Product_Action_Type_List_Request'); $request->setParams($this->params); $request->setListingProduct($listingProduct); $request->setConfigurator($this->getConfigurator()); $request->setValidatorsData($this->getValidatorsData($listingProduct)); $this->requestsObjects[$listingProduct->getId()] = $request; } return $this->requestsObjects[$listingProduct->getId()]; }
protected function unlockListingProduct() { $lockItem = Mage::getModel('M2ePro/LockItem'); $lockItem->setNick(Ess_M2ePro_Helper_Component_Ebay::NICK . '_listing_product_' . $this->listingProduct->getId()); $lockItem->remove(); }
/** * @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->isLockedObject('in_action')) { return false; } $amazonSynchronizationTemplate = $amazonListingProduct->getAmazonSynchronizationTemplate(); $variationResource = Mage::getResourceModel('M2ePro/Listing_Product_Variation'); 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 getListingProductSendedNativeData(Ess_M2ePro_Model_Listing_Product $listingProduct) { return (array) $this->params['products'][$listingProduct->getId()]['request']['sended_data']; }
private function logChangeOfStatus(Ess_M2ePro_Model_Listing_Product $listingProduct, $status) { $message = ''; switch ($status) { case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED: // M2ePro_TRANSLATIONS // Item status was successfully changed to "Listed". $message = 'Item status was successfully changed to "Listed".'; break; case Ess_M2ePro_Model_Listing_Product::STATUS_HIDDEN: // M2ePro_TRANSLATIONS // Item status was successfully changed to "Listed(Hidden)". $message = 'Item status was successfully changed to "Listed(Hidden)".'; break; case Ess_M2ePro_Model_Listing_Product::STATUS_SOLD: // M2ePro_TRANSLATIONS // Item status was successfully changed to "Sold". $message = 'Item status was successfully changed to "Sold".'; break; case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED: // M2ePro_TRANSLATIONS // Item status was successfully changed to "Stopped". $message = 'Item status was successfully changed to "Stopped".'; break; case Ess_M2ePro_Model_Listing_Product::STATUS_FINISHED: // M2ePro_TRANSLATIONS // Item status was successfully changed to "Finished". $message = 'Item status was successfully changed to "Finished".'; break; } $log = Mage::getModel('M2ePro/Listing_Log'); $log->setComponentMode(Ess_M2ePro_Helper_Component_Ebay::NICK); $log->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION, $this->getLogsActionId(), Ess_M2ePro_Model_Listing_Log::ACTION_CHANGE_STATUS_ON_CHANNEL, $message, Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS, Ess_M2ePro_Model_Log_Abstract::PRIORITY_LOW); }
private function isMeetListRequirements(Ess_M2ePro_Model_Listing_Product $listingProduct) { // Is checked before? //-------------------- if (in_array($listingProduct->getId(), $this->_checkedListingsProductsIds)) { return false; } else { $this->_checkedListingsProductsIds[] = $listingProduct->getId(); } //-------------------- // eBay available status //-------------------- if (!$listingProduct->isNotListed()) { return false; } if (!$listingProduct->isListable()) { return false; } if ($this->_runnerActions->isExistProductAction($listingProduct, Ess_M2ePro_Model_Connector_Server_Ebay_Item_Dispatcher::ACTION_LIST, array())) { return false; } //-------------------- // Correct synchronization //-------------------- if (!$listingProduct->getListing()->isSynchronizationNowRun()) { return false; } if (!$listingProduct->getSynchronizationTemplate()->getChildObject()->isListMode()) { return false; } //-------------------- $uniqueOptionsProductsIds = NULL; // Check filters //-------------------- if ($listingProduct->getSynchronizationTemplate()->getChildObject()->isListStatusEnabled()) { if ($listingProduct->getMagentoProduct()->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED) { return false; } else { if (is_null($uniqueOptionsProductsIds)) { $uniqueOptionsProductsIds = $listingProduct->getUniqueOptionsProductsIds(); } if (count($uniqueOptionsProductsIds) > 0) { $statusesTemp = $listingProduct->getUniqueOptionsProductsStatuses($uniqueOptionsProductsIds); if ((int) min($statusesTemp) == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) { return false; } } } } if ($listingProduct->getSynchronizationTemplate()->getChildObject()->isListIsInStock()) { if (!$listingProduct->getMagentoProduct()->getStockAvailability()) { return false; } else { if (is_null($uniqueOptionsProductsIds)) { $uniqueOptionsProductsIds = $listingProduct->getUniqueOptionsProductsIds(); } if (count($uniqueOptionsProductsIds) > 0) { $stockAvailabilityTemp = $listingProduct->getUniqueOptionsProductsStockAvailability($uniqueOptionsProductsIds); if (!(int) max($stockAvailabilityTemp)) { return false; } } } } if ($listingProduct->getSynchronizationTemplate()->getChildObject()->isListWhenQtyHasValue()) { $result = false; $productQty = (int) $listingProduct->getChildObject()->getQty(true); $ebaySynchronizationTemplate = $listingProduct->getSynchronizationTemplate()->getChildObject(); $typeQty = (int) $ebaySynchronizationTemplate->getListWhenQtyHasValueType(); $minQty = (int) $ebaySynchronizationTemplate->getListWhenQtyHasValueMin(); $maxQty = (int) $ebaySynchronizationTemplate->getListWhenQtyHasValueMax(); if ($typeQty == Ess_M2ePro_Model_Ebay_Template_Synchronization::LIST_QTY_LESS && $productQty <= $minQty) { $result = true; } if ($typeQty == Ess_M2ePro_Model_Ebay_Template_Synchronization::LIST_QTY_MORE && $productQty >= $minQty) { $result = true; } if ($typeQty == Ess_M2ePro_Model_Ebay_Template_Synchronization::LIST_QTY_BETWEEN && $productQty >= $minQty && $productQty <= $maxQty) { $result = true; } if (!$result) { return false; } } //-------------------- return true; }
/** * @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; } $variationResource = Mage::getResourceModel('M2ePro/Listing_Product_Variation'); 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; }
private function addNewVariations(Ess_M2ePro_Model_Listing_Product $listingProduct, $addedVariations) { foreach ($addedVariations as $aVariation) { if (isset($aVariation['variation']['id'])) { $dataForUpdate = array('add' => 1, 'delete' => 0); Mage::helper('M2ePro/Component')->getComponentObject(Ess_M2ePro_Helper_Component_Ebay::NICK, 'Listing_Product_Variation', $aVariation['variation']['id'])->addData($dataForUpdate)->save(); continue; } $dataForAdd = array('listing_product_id' => $listingProduct->getId(), 'add' => 1, 'delete' => 0, 'status' => Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED); $newVariationId = Mage::helper('M2ePro/Component')->getComponentModel(Ess_M2ePro_Helper_Component_Ebay::NICK, 'Listing_Product_Variation')->addData($dataForAdd)->save()->getId(); foreach ($aVariation['options'] as $aOption) { $dataForAdd = array('listing_product_variation_id' => $newVariationId, 'product_id' => $aOption['product_id'], 'product_type' => $aOption['product_type'], 'attribute' => $aOption['attribute'], 'option' => $aOption['option']); Mage::helper('M2ePro/Component')->getComponentModel(Ess_M2ePro_Helper_Component_Ebay::NICK, 'Listing_Product_Variation_Option')->addData($dataForAdd)->save(); } } }
public function inspectRevisePriceRequirements(Ess_M2ePro_Model_Listing_Product $listingProduct) { // Is checked before? //-------------------- if (in_array($listingProduct->getId(), $this->_checkedPriceListingsProductsIds)) { return false; } else { $this->_checkedPriceListingsProductsIds[] = $listingProduct->getId(); } //-------------------- // Prepare actions params //-------------------- $actionParams = array('only_data' => array('price' => true)); //-------------------- // Play available status //-------------------- if (!$listingProduct->isListed()) { return false; } if (!$listingProduct->isRevisable()) { return false; } if ($this->_runnerActions->isExistProductAction($listingProduct, Ess_M2ePro_Model_Connector_Server_Play_Product_Dispatcher::ACTION_REVISE, $actionParams)) { return false; } if ($listingProduct->isLockedObject(NULL) || $listingProduct->isLockedObject('in_action')) { return false; } //-------------------- // Correct synchronization //-------------------- if (!$listingProduct->getChildObject()->getPlaySynchronizationTemplate()->isReviseWhenChangePrice()) { return false; } //-------------------- // Check filters //-------------------- $onlinePriceGbr = $listingProduct->getChildObject()->getOnlinePriceGbr(); $currentPriceGbr = $listingProduct->getChildObject()->getPriceGbr(true); if ($currentPriceGbr != $onlinePriceGbr) { $this->_runnerActions->setProduct($listingProduct, Ess_M2ePro_Model_Connector_Server_Play_Product_Dispatcher::ACTION_REVISE, $actionParams); return true; } $onlinePriceEuro = $listingProduct->getChildObject()->getOnlinePriceEuro(); $currentPriceEuro = $listingProduct->getChildObject()->getPriceEuro(true); if ($onlinePriceEuro != $currentPriceEuro) { $this->_runnerActions->setProduct($listingProduct, Ess_M2ePro_Model_Connector_Server_Play_Product_Dispatcher::ACTION_REVISE, $actionParams); return true; } //-------------------- return false; }
private function prepareChangedListingsProducts(Ess_M2ePro_Model_Listing_Product $tempListingProductModel, $ebayChange) { /** @var $tempEbayListingProductModel Ess_M2ePro_Model_Ebay_Listing_Product */ $tempEbayListingProductModel = $tempListingProductModel->getChildObject(); // Prepare eBay changes values //-------------------------- $tempEbayChanges = array(); if ($tempEbayListingProductModel->isListingTypeAuction()) { $tempEbayChanges['online_start_price'] = (double) $ebayChange['currentPrice'] < 0 ? 0 : (double) $ebayChange['currentPrice']; } if ($tempEbayListingProductModel->isListingTypeFixed()) { $tempEbayChanges['online_buyitnow_price'] = (double) $ebayChange['currentPrice'] < 0 ? 0 : (double) $ebayChange['currentPrice']; } $tempEbayChanges['online_qty'] = (int) $ebayChange['quantity'] < 0 ? 0 : (int) $ebayChange['quantity']; $tempEbayChanges['online_qty_sold'] = (int) $ebayChange['quantitySold'] < 0 ? 0 : (int) $ebayChange['quantitySold']; if ($tempEbayListingProductModel->isListingTypeAuction()) { $tempEbayChanges['online_qty'] = 1; $tempEbayChanges['online_bids'] = (int) $ebayChange['bidCount'] < 0 ? 0 : (int) $ebayChange['bidCount']; } $tempEbayChanges['start_date'] = Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($ebayChange['startTime']); $tempEbayChanges['end_date'] = Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($ebayChange['endTime']); if ($tempEbayChanges['online_qty'] == $tempEbayChanges['online_qty_sold'] && ($ebayChange['listingStatus'] == self::EBAY_STATUS_COMPLETED || $ebayChange['listingStatus'] == self::EBAY_STATUS_ENDED)) { $tempEbayChanges['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_SOLD; } else { if ($ebayChange['listingStatus'] == self::EBAY_STATUS_COMPLETED) { $tempEbayChanges['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED; } else { if ($ebayChange['listingStatus'] == self::EBAY_STATUS_ENDED) { $tempEbayChanges['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_FINISHED; } else { if ($ebayChange['listingStatus'] == self::EBAY_STATUS_ACTIVE) { $tempEbayChanges['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_LISTED; } } } } if ($tempListingProductModel->getStatus() != $tempEbayChanges['status'] || $tempListingProductModel->getChildObject()->getOnlineQty() != $tempEbayChanges['online_qty'] || $tempListingProductModel->getChildObject()->getOnlineQtySold() != $tempEbayChanges['online_qty_sold']) { Mage::getModel('M2ePro/ProductChange')->addUpdateAction($tempListingProductModel->getProductId(), Ess_M2ePro_Model_ProductChange::CREATOR_TYPE_SYNCHRONIZATION); } if ($tempEbayChanges['status'] != $tempListingProductModel->getStatus()) { $tempEbayChanges['status_changer'] = Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_COMPONENT; $tempLogMessage = ''; switch ($tempEbayChanges['status']) { case Ess_M2ePro_Model_Listing_Product::STATUS_LISTED: // Parser hack -> Mage::helper('M2ePro')->__('Item status was successfully changed to "Listed".'); $tempLogMessage = 'Item status was successfully changed to "Listed".'; break; case Ess_M2ePro_Model_Listing_Product::STATUS_SOLD: // Parser hack -> Mage::helper('M2ePro')->__('Item status was successfully changed to "Sold".'); $tempLogMessage = 'Item status was successfully changed to "Sold".'; break; case Ess_M2ePro_Model_Listing_Product::STATUS_STOPPED: // Parser hack -> Mage::helper('M2ePro')->__('Item status was successfully changed to "Stopped".'); $tempLogMessage = 'Item status was successfully changed to "Stopped".'; break; case Ess_M2ePro_Model_Listing_Product::STATUS_FINISHED: // Parser hack -> Mage::helper('M2ePro')->__('Item status was successfully changed to "Finished".'); $tempLogMessage = 'Item status was successfully changed to "Finished".'; break; } $tempLog = Mage::getModel('M2ePro/Listing_Log'); $tempLog->setComponentMode(Ess_M2ePro_Helper_Component_Ebay::NICK); $tempLog->addProductMessage($tempListingProductModel->getListingId(), $tempListingProductModel->getProductId(), $tempListingProductModel->getId(), Ess_M2ePro_Model_Log_Abstract::INITIATOR_EXTENSION, $this->getLogActionId(), Ess_M2ePro_Model_Listing_Log::ACTION_CHANGE_STATUS_ON_CHANNEL, $tempLogMessage, Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS, Ess_M2ePro_Model_Log_Abstract::PRIORITY_LOW); } //-------------------------- // Create changed listings products //-------------------------- $changedListingsProducts = array('ebay_item_id' => $ebayChange['id'], 'listing_product' => array('instance' => $tempListingProductModel, 'changes' => $tempEbayChanges), 'listings_products_variations' => array()); //-------------------------- // Cancel when have not eBay variations //-------------------------- if (!isset($ebayChange['variations']) || is_null($ebayChange['variations'])) { return $changedListingsProducts; } //-------------------------- // Get listings products variations //----------------------- $tempVariations = $tempListingProductModel->getVariations(true); if (count($tempVariations) == 0) { return $changedListingsProducts; } //----------------------- // Get listings products variations with options //----------------------- $tempVariationsWithOptions = array(); foreach ($tempVariations as $variation) { /** @var $variation Ess_M2ePro_Model_Listing_Product_Variation */ $options = $variation->getOptions(true); if (count($options) == 0) { continue; } $tempVariationsWithOptions[] = array('variation' => $variation, 'options' => $options); } if (count($tempVariationsWithOptions) == 0) { return $changedListingsProducts; } //----------------------- // Search our variations for eBay variations //-------------------------- foreach ($ebayChange['variations'] as $ebayVariation) { // Find our variation //-------------------------- foreach ($tempVariationsWithOptions as $M2eProVariation) { $equalVariation = true; foreach ($M2eProVariation['options'] as $M2eProOptionValue) { $haveOption = false; foreach ($ebayVariation['specifics'] as $ebayOptionKey => $ebayOptionValue) { if ($M2eProOptionValue->getData('attribute') == $ebayOptionKey && $M2eProOptionValue->getData('option') == $ebayOptionValue) { $haveOption = true; break; } } if ($haveOption === false) { $equalVariation = false; break; } } if ($equalVariation === true && count($M2eProVariation['options']) == count($ebayVariation['specifics'])) { // Prepare eBay changes values //-------------------------- $tempEbayChanges = array(); $tempEbayChanges['online_price'] = (double) $ebayVariation['price'] < 0 ? 0 : (double) $ebayVariation['price']; $tempEbayChanges['online_qty'] = (int) $ebayVariation['quantity'] < 0 ? 0 : (int) $ebayVariation['quantity']; $tempEbayChanges['online_qty_sold'] = (int) $ebayVariation['quantitySold'] < 0 ? 0 : (int) $ebayVariation['quantitySold']; if ($tempEbayChanges['online_qty'] <= $tempEbayChanges['online_qty_sold']) { $tempEbayChanges['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_SOLD; } if ($tempEbayChanges['online_qty'] <= 0) { $tempEbayChanges['status'] = Ess_M2ePro_Model_Listing_Product::STATUS_NOT_LISTED; } //-------------------------- // Add changed variation //-------------------------- $changedListingsProducts['listings_products_variations'][] = array('instance' => $M2eProVariation, 'changes' => $tempEbayChanges); //-------------------------- break; } } //-------------------------- } return $changedListingsProducts; }
private function logReportChange(Ess_M2ePro_Model_Listing_Product $listingProduct, $logMessage) { if (empty($logMessage)) { return; } $log = Mage::getModel('M2ePro/Listing_Log'); $log->setComponentMode(Ess_M2ePro_Helper_Component_Ebay::NICK); $log->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), Ess_M2ePro_Helper_Data::INITIATOR_EXTENSION, $this->getLogsActionId(), Ess_M2ePro_Model_Listing_Log::ACTION_CHANNEL_CHANGE, $logMessage, Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS, Ess_M2ePro_Model_Log_Abstract::PRIORITY_LOW); }
private function inspectRevisePriceRequirements(Ess_M2ePro_Model_Listing_Product $listingProduct) { // Is checked before? //-------------------- if (in_array($listingProduct->getId(), $this->_checkedPriceListingsProductsIds)) { return false; } else { $this->_checkedPriceListingsProductsIds[] = $listingProduct->getId(); } //-------------------- // Prepare actions params //-------------------- $actionParams = array('only_data' => array('price' => true, 'variations' => true)); //-------------------- // eBay available status //-------------------- if (!$listingProduct->isListed()) { return false; } if (!$listingProduct->isRevisable()) { return false; } if ($this->_runnerActions->isExistProductAction($listingProduct, Ess_M2ePro_Model_Connector_Ebay_Item_Dispatcher::ACTION_REVISE, $actionParams)) { return false; } //-------------------- // Correct synchronization //-------------------- if (!$listingProduct->getChildObject()->isSetCategoryTemplate()) { return false; } if (!$listingProduct->getChildObject()->getEbaySynchronizationTemplate()->isReviseWhenChangePrice()) { return false; } //-------------------- // Check filters //-------------------- $isVariationProduct = $listingProduct->getChildObject()->isVariationMode() && count($listingProduct->getVariations()) > 0; if (!$isVariationProduct) { $hasChange = false; //--------- $currentPrice = $listingProduct->getChildObject()->getBuyItNowPrice(); $onlinePrice = $listingProduct->getChildObject()->getOnlineBuyItNowPrice(); if ($currentPrice != $onlinePrice) { $hasChange = true; } if ($hasChange) { $this->_runnerActions->setProduct($listingProduct, Ess_M2ePro_Model_Connector_Ebay_Item_Dispatcher::ACTION_REVISE, $actionParams); return true; } //--------- if ($listingProduct->getChildObject()->isListingTypeAuction()) { //--------- $currentPrice = $listingProduct->getChildObject()->getStartPrice(); $onlinePrice = $listingProduct->getChildObject()->getOnlineStartPrice(); if ($currentPrice != $onlinePrice) { $hasChange = true; } if ($hasChange) { $this->_runnerActions->setProduct($listingProduct, Ess_M2ePro_Model_Connector_Ebay_Item_Dispatcher::ACTION_REVISE, $actionParams); return true; } //--------- $currentPrice = $listingProduct->getChildObject()->getReservePrice(); $onlinePrice = $listingProduct->getChildObject()->getOnlineReservePrice(); if ($currentPrice != $onlinePrice) { $hasChange = true; } if ($hasChange) { $this->_runnerActions->setProduct($listingProduct, Ess_M2ePro_Model_Connector_Ebay_Item_Dispatcher::ACTION_REVISE, $actionParams); return true; } //--------- } } else { $variations = $listingProduct->getVariations(true); foreach ($variations as $variation) { $currentPrice = $variation->getChildObject()->getPrice(); $onlinePrice = $variation->getChildObject()->getOnlinePrice(); if ($currentPrice != $onlinePrice) { $this->_runnerActions->setProduct($listingProduct, Ess_M2ePro_Model_Connector_Ebay_Item_Dispatcher::ACTION_REVISE, $actionParams); return true; } } } //-------------------- return false; }
public function getResponserParams() { return array('listing_product_id' => $this->listingProduct->getId(), 'step' => $this->getCurrentStep()); }
public function inspectRevisePriceRequirements(Ess_M2ePro_Model_Listing_Product $listingProduct) { // Is checked before? //-------------------- if (in_array($listingProduct->getId(), $this->_checkedPriceListingsProductsIds)) { return false; } else { $this->_checkedPriceListingsProductsIds[] = $listingProduct->getId(); } //-------------------- // Prepare actions params //-------------------- $actionParams = array('only_data' => array('price' => true)); //-------------------- // Amazon available status //-------------------- if (!$listingProduct->isListed() || $listingProduct->isBlocked()) { return false; } if (!$listingProduct->isRevisable()) { return false; } if ($this->getRunner()->isExistProduct($listingProduct, Ess_M2ePro_Model_Listing_Product::ACTION_REVISE, $actionParams)) { return false; } if ($listingProduct->isLockedObject(NULL) || $listingProduct->isLockedObject('in_action')) { return false; } //-------------------- /* @var $amazonSynchronizationTemplate Ess_M2ePro_Model_Amazon_Template_Synchronization */ $amazonSynchronizationTemplate = $listingProduct->getChildObject()->getAmazonSynchronizationTemplate(); // Correct synchronization //-------------------- if (!$amazonSynchronizationTemplate->isReviseWhenChangePrice()) { return false; } if ($listingProduct->getChildObject()->isVariationProduct() && !$listingProduct->getChildObject()->isVariationMatched()) { return false; } //-------------------- // Check filters //-------------------- $currentPrice = $listingProduct->getChildObject()->getPrice(); $onlinePrice = $listingProduct->getChildObject()->getOnlinePrice(); if ($currentPrice != $onlinePrice) { $this->getRunner()->addProduct($listingProduct, Ess_M2ePro_Model_Listing_Product::ACTION_REVISE, $actionParams); return true; } $currentSalePriceInfo = $listingProduct->getChildObject()->getSalePriceInfo(); $currentSalePrice = $currentSalePriceInfo['price']; $onlineSalePrice = $listingProduct->getChildObject()->getOnlineSalePrice(); if (is_null($currentSalePrice) && !is_null($onlineSalePrice) || !is_null($currentSalePrice) && is_null($onlineSalePrice) || (double) $currentSalePrice != (double) $onlineSalePrice) { $this->getRunner()->addProduct($listingProduct, Ess_M2ePro_Model_Listing_Product::ACTION_REVISE, $actionParams); return true; } //-------------------- //-------------------- $currentSalePriceStartDate = $currentSalePriceInfo['start_date']; $onlineSalePriceStartDate = $listingProduct->getChildObject()->getOnlineSalePriceStartDate(); $currentSalePriceEndDate = $currentSalePriceInfo['end_date']; $onlineSalePriceEndDate = $listingProduct->getChildObject()->getOnlineSalePriceEndDate(); if ($currentSalePriceStartDate != $onlineSalePriceStartDate || $currentSalePriceEndDate != $onlineSalePriceEndDate) { $this->getRunner()->addProduct($listingProduct, Ess_M2ePro_Model_Listing_Product::ACTION_REVISE, $actionParams); return true; } //-------------------- return false; }
/** * @param Ess_M2ePro_Model_Listing_Product $listingProduct * @return string */ public function getViewLogIconHtml($listingProduct) { $listingProductId = (int) $listingProduct->getId(); // Get last messages // --------------------------------------- /** @var $connRead Varien_Db_Adapter_Pdo_Mysql */ $connRead = Mage::getSingleton('core/resource')->getConnection('core_read'); $dbSelect = $connRead->select()->from(Mage::getResourceModel('M2ePro/Listing_Log')->getMainTable(), array('action_id', 'action', 'type', 'description', 'create_date', 'initiator'))->where('`listing_product_id` = ?', $listingProductId)->where('`action_id` IS NOT NULL')->order(array('id DESC'))->limit(30); $logRows = $connRead->fetchAll($dbSelect); // --------------------------------------- // Get grouped messages by action_id // --------------------------------------- $actionsRows = array(); $tempActionRows = array(); $lastActionId = false; foreach ($logRows as $row) { $row['description'] = Mage::helper('M2ePro/View')->getModifiedLogMessage($row['description']); if ($row['action_id'] !== $lastActionId) { if (count($tempActionRows) > 0) { $actionsRows[] = array('type' => $this->getMainTypeForActionId($tempActionRows), 'date' => $this->getMainDateForActionId($tempActionRows), 'action' => $this->getActionForAction($tempActionRows[0]), 'initiator' => $this->getInitiatorForAction($tempActionRows[0]), 'items' => $tempActionRows); $tempActionRows = array(); } $lastActionId = $row['action_id']; } $tempActionRows[] = $row; } if (count($tempActionRows) > 0) { $actionsRows[] = array('type' => $this->getMainTypeForActionId($tempActionRows), 'date' => $this->getMainDateForActionId($tempActionRows), 'action' => $this->getActionForAction($tempActionRows[0]), 'initiator' => $this->getInitiatorForAction($tempActionRows[0]), 'items' => $tempActionRows); } if (count($actionsRows) <= 0) { return ''; } foreach ($actionsRows as &$actionsRow) { usort($actionsRow['items'], function ($a, $b) { $sortOrder = array(Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 1, Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 2, Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 3); return $sortOrder[$a["type"]] > $sortOrder[$b["type"]]; }); } $tips = array(Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'Last Action was completed successfully.', Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'Last Action was completed with error(s).', Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'Last Action was completed with warning(s).'); $icons = array(Ess_M2ePro_Model_Log_Abstract::TYPE_SUCCESS => 'normal', Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR => 'error', Ess_M2ePro_Model_Log_Abstract::TYPE_WARNING => 'warning'); $summary = $this->getLayout()->createBlock('M2ePro/adminhtml_log_grid_summary', '', array('entity_id' => (int) $listingProduct->getId(), 'rows' => $actionsRows, 'tips' => $tips, 'icons' => $icons, 'view_help_handler' => 'ListingGridHandlerObj.viewItemHelp', 'hide_help_handler' => 'ListingGridHandlerObj.hideItemHelp')); return $summary->toHtml(); }
/** * @param Ess_M2ePro_Model_Listing_Product $listingProduct * @param $message * @param int $type * @param int $priority */ public function logListingProductMessage(Ess_M2ePro_Model_Listing_Product $listingProduct, $message, $type = Ess_M2ePro_Model_Log_Abstract::TYPE_ERROR, $priority = Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM) { $this->setStatusByMessageType($type); $this->getListingLog()->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), $this->initiator, $this->actionId, $this->action, $message, $type, $priority); }