Example #1
0
 protected function logError(\Ess\M2ePro\Model\Listing\Product $listingProduct, \Exception $exception)
 {
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Log $logModel */
     $logModel = $this->activeRecordFactory->getObject('Amazon\\Listing\\Log');
     $logModel->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), \Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION, $logModel->getNextActionId(), $this->getActionForLog(), $exception->getMessage(), \Ess\M2ePro\Model\Log\AbstractLog::TYPE_ERROR, \Ess\M2ePro\Model\Log\AbstractLog::PRIORITY_HIGH);
     $this->getHelper('Module\\Exception')->process($exception);
 }
Example #2
0
 protected function processAddedListingProduct(\Ess\M2ePro\Model\Listing\Product $listingProduct, array $params)
 {
     $ebayListingProduct = $listingProduct->getChildObject();
     if (!empty($params['template_category_id'])) {
         $ebayListingProduct->setData('template_category_id', $params['template_category_id']);
     }
     if (!empty($params['template_other_category_id'])) {
         $ebayListingProduct->setData('template_other_category_id', $params['template_other_category_id']);
     }
     $listingProduct->save();
 }
 protected function getSuccessfulParams(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     $responseData = $this->getPreparedResponseData();
     if (!is_array($responseData['asins']) || empty($responseData['asins'])) {
         return array();
     }
     foreach ($responseData['asins'] as $key => $asin) {
         if ((int) $key != (int) $listingProduct->getId()) {
             continue;
         }
         return array('general_id' => $asin);
     }
     return array();
 }
Example #4
0
 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;
 }
Example #5
0
 protected function markAsPotentialDuplicate()
 {
     $additionalData = $this->listingProduct->getAdditionalData();
     $additionalData['last_failed_action_data'] = array('native_request_data' => $this->getRequestDataObject()->getData(), 'previous_status' => $this->listingProduct->getStatus(), 'action' => $this->getActionType(), 'request_time' => $this->getResponse()->getRequestTime());
     $this->listingProduct->addData(array('status' => \Ess\M2ePro\Model\Listing\Product::STATUS_BLOCKED, 'additional_data' => json_encode($additionalData)))->save();
     $this->listingProduct->getChildObject()->updateVariationsStatus();
 }
Example #6
0
 protected function isChangeInitiatorOnlyInspector(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     $changeInitiators = $listingProduct->getData('change_initiators');
     if (empty($changeInitiators)) {
         return false;
     }
     $changeInitiators = (array) explode(',', $changeInitiators);
     $changeInitiators = array_unique($changeInitiators);
     if (count($changeInitiators) != 1) {
         return false;
     }
     if ((int) reset($changeInitiators) != \Ess\M2ePro\Model\ProductChange::INITIATOR_INSPECTOR) {
         return false;
     }
     return true;
 }
Example #7
0
 private function getConnectorParams()
 {
     $searchMethod = $this->getSearchMethod();
     /** @var \Ess\M2ePro\Model\Listing\Product $amazonListingProduct */
     $amazonListingProduct = $this->listingProduct->getChildObject();
     $isModifyChildToSimple = !$amazonListingProduct->getVariationManager()->isRelationParentType();
     $params = array('variation_bad_parent_modify_child_to_simple' => $isModifyChildToSimple);
     if ($searchMethod == 'byQuery') {
         $params['query'] = $this->query;
     } else {
         $params['query'] = $this->getStrippedQuery();
     }
     if ($searchMethod == 'byIdentifier') {
         $params['query_type'] = $this->getIdentifierType();
     }
     return $params;
 }
Example #8
0
 private function getItemDataByListingProduct(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     $connectorName = ucfirst($listingProduct->getComponentMode()) . '\\Connector\\';
     $connectorName .= $listingProduct->isComponentModeEbay() ? 'Item' : 'Product';
     $connectorName .= '\\Stop\\MultipleRequester';
     $connectorParams = array('logs_action_id' => 0, 'status_changer' => \Ess\M2ePro\Model\Listing\Product::STATUS_CHANGER_UNKNOWN);
     try {
         $dispatcher = $this->modelFactory->getObject(ucfirst($listingProduct->getComponentMode()) . '_Connector\\Dispatcher');
         $connector = $dispatcher->getCustomConnector($connectorName, $connectorParams);
         $connector->setListingsProducts(array($listingProduct));
         $itemData = $connector->getRequestDataPackage();
     } catch (\Exception $exception) {
         return NULL;
     }
     if (!isset($itemData['data']['items'])) {
         return NULL;
     }
     return array_shift($itemData['data']['items']);
 }
Example #9
0
 /**
  * @return \Ess\M2ePro\Model\Ebay\Listing\Product\Action\Type\Request
  */
 protected function makeRequestObject()
 {
     /** @var \Ess\M2ePro\Model\Ebay\Listing\Product\Action\Type\Request $request */
     $request = $this->modelFactory->getObject('Ebay\\Listing\\Product\\Action\\Type\\' . $this->getOrmActionType() . '\\Request');
     $request->setParams($this->params);
     $request->setListingProduct($this->listingProduct);
     $request->setConfigurator($this->listingProduct->getActionConfigurator());
     $request->setValidatorsData($this->getValidatorObject($this->listingProduct)->getData());
     return $request;
 }
Example #10
0
 private function prepareConfigurator(\Ess\M2ePro\Model\Listing\Product $listingProduct, \Ess\M2ePro\Model\Ebay\Listing\Product\Action\Configurator $configurator, $action)
 {
     if ($action != \Ess\M2ePro\Model\Listing\Product::ACTION_STOP) {
         $configurator->setParams(array('replaced_action' => \Ess\M2ePro\Model\Listing\Product::ACTION_STOP));
     }
     /** @var \Ess\M2ePro\Model\Ebay\Listing\Product $ebayListingProduct */
     $ebayListingProduct = $listingProduct->getChildObject();
     if (!$ebayListingProduct->isOutOfStockControlEnabled() && $action == \Ess\M2ePro\Model\Listing\Product::ACTION_STOP) {
         return;
     }
     $configurator->setPartialMode();
     $configurator->allowQty()->allowVariations();
 }
Example #11
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 #12
0
 private function logListingProductMessage(\Ess\M2ePro\Model\Listing\Product $listingProduct, $action, $oldValue, $newValue)
 {
     // M2ePro\TRANSLATIONS
     // From [%from%] to [%to%].
     $log = $this->activeRecordFactory->getObject('Listing\\Log');
     $log->setComponentMode($listingProduct->getComponentMode());
     $log->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), \Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION, NULL, $action, $log->encodeDescription('From [%from%] to [%to%].', array('from' => $oldValue, 'to' => $newValue)), \Ess\M2ePro\Model\Log\AbstractLog::TYPE_NOTICE, \Ess\M2ePro\Model\Log\AbstractLog::PRIORITY_LOW);
 }
Example #13
0
 private function setListAttemptData(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     $additionalData = $listingProduct->getAdditionalData();
     $additionalData['last_list_attempt_date'] = $this->getHelper('Data')->getCurrentGmtDate();
     $listingProduct->setSettings('additional_data', $additionalData);
     $listingProduct->save();
 }
Example #14
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 #15
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @return \Ess\M2ePro\Model\Ebay\Listing\Product\Action\RequestData
  */
 protected function getRequestDataObject(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     if (!isset($this->requestsDataObjects[$listingProduct->getId()])) {
         /** @var \Ess\M2ePro\Model\Ebay\Listing\Product\Action\RequestData $requestData */
         $requestData = $this->modelFactory->getObject('Ebay\\Listing\\Product\\Action\\RequestData');
         $requestData->setData($this->params['products'][$listingProduct->getId()]['request']);
         $requestData->setListingProduct($listingProduct);
         $this->requestsDataObjects[$listingProduct->getId()] = $requestData;
     }
     return $this->requestsDataObjects[$listingProduct->getId()];
 }
 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 #17
0
 private function matchEmptyChannelOptionsChild(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Variation\Manager\Type\Relation\ChildRelation $typeModel */
     $typeModel = $listingProduct->getChildObject()->getVariationManager()->getTypeModel();
     $channelOptions = array_merge($this->getProcessor()->getTypeModel()->getUnusedChannelOptions(), $this->getProcessor()->getTypeModel()->getUsedChannelOptions(true));
     if (empty($channelOptions)) {
         return;
     }
     if (!$typeModel->isVariationProductMatched()) {
         return;
     }
     $matcher = $this->getOptionMatcher();
     $matcher->setDestinationOptions($channelOptions);
     $generalId = $matcher->getMatchedOptionGeneralId($typeModel->getProductOptions());
     if (is_null($generalId)) {
         return;
     }
     $existChild = $this->findChildByChannelOptions($channelOptions[$generalId]);
     if (!is_null($existChild)) {
         $this->getProcessor()->tryToRemoveChildListingProduct($existChild);
     }
     $listingProduct->getChildObject()->setData('general_id', $generalId);
     $typeModel->setChannelVariation($channelOptions[$generalId]);
 }
 protected function addListingsProductsLogsMessage(\Ess\M2ePro\Model\Listing\Product $listingProduct, $text, $type = \Ess\M2ePro\Model\Log\AbstractLog::TYPE_NOTICE, $priority = \Ess\M2ePro\Model\Log\AbstractLog::PRIORITY_MEDIUM)
 {
     $action = \Ess\M2ePro\Model\Listing\Log::ACTION_TRANSLATE_PRODUCT;
     if ($this->params['status_changer'] == \Ess\M2ePro\Model\Listing\Product::STATUS_CHANGER_UNKNOWN) {
         $initiator = \Ess\M2ePro\Helper\Data::INITIATOR_UNKNOWN;
     } else {
         if ($this->params['status_changer'] == \Ess\M2ePro\Model\Listing\Product::STATUS_CHANGER_USER) {
             $initiator = \Ess\M2ePro\Helper\Data::INITIATOR_USER;
         } else {
             $initiator = \Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION;
         }
     }
     switch ($type) {
         case \Ess\M2ePro\Model\Log\AbstractLog::TYPE_ERROR:
             $this->setStatus(\Ess\M2ePro\Helper\Data::STATUS_ERROR);
             break;
         case \Ess\M2ePro\Model\Log\AbstractLog::TYPE_WARNING:
             $this->setStatus(\Ess\M2ePro\Helper\Data::STATUS_WARNING);
             break;
         case \Ess\M2ePro\Model\Log\AbstractLog::TYPE_SUCCESS:
         case \Ess\M2ePro\Model\Log\AbstractLog::TYPE_NOTICE:
             $this->setStatus(\Ess\M2ePro\Helper\Data::STATUS_SUCCESS);
             break;
         default:
             $this->setStatus(\Ess\M2ePro\Helper\Data::STATUS_ERROR);
             break;
     }
     $logModel = $this->activeRecordFactory->getObject('Listing\\Log');
     $logModel->setComponentMode(\Ess\M2ePro\Helper\Component\Ebay::NICK);
     $logModel->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), $initiator, $this->logsActionId, $action, $text, $type, $priority);
 }
Example #19
0
 private function prepareConfigurator(\Ess\M2ePro\Model\Listing\Product $listingProduct, \Ess\M2ePro\Model\Ebay\Listing\Product\Action\Configurator $configurator, $action)
 {
     if ($action != \Ess\M2ePro\Model\Listing\Product::ACTION_RELIST) {
         $configurator->setParams(array('replaced_action' => \Ess\M2ePro\Model\Listing\Product::ACTION_RELIST));
     }
     /** @var \Ess\M2ePro\Model\Ebay\Listing\Product $ebayListingProduct */
     $ebayListingProduct = $listingProduct->getChildObject();
     if (!$ebayListingProduct->getEbaySynchronizationTemplate()->isRelistSendData()) {
         $configurator->setPartialMode();
         $configurator->allowQty()->allowPrice()->allowVariations();
     }
 }
Example #20
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @return bool
  * @throws \Ess\M2ePro\Model\Exception\Logic
  */
 public function isMeetReviseSynchReasonsRequirements(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     $reasons = $listingProduct->getSynchReasons();
     if (empty($reasons)) {
         return false;
     }
     if (!$this->isMeetReviseGeneralRequirements($listingProduct)) {
         return false;
     }
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product $amazonListingProduct */
     $amazonListingProduct = $listingProduct->getChildObject();
     $synchronizationTemplate = $amazonListingProduct->getSynchronizationTemplate();
     $amazonSynchronizationTemplate = $amazonListingProduct->getAmazonSynchronizationTemplate();
     foreach ($reasons as $reason) {
         $method = 'isRevise' . ucfirst($reason);
         if (method_exists($synchronizationTemplate, $method)) {
             if ($synchronizationTemplate->{$method}()) {
                 return true;
             }
             continue;
         }
         if (method_exists($amazonSynchronizationTemplate, $method)) {
             if ($amazonSynchronizationTemplate->{$method}()) {
                 return true;
             }
             continue;
         }
     }
     return false;
 }
Example #21
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @return \Ess\M2ePro\Model\Ebay\Listing\Product\Action\RequestData
  */
 protected function getRequestDataObject(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     return $this->requestsDataObjects[$listingProduct->getId()];
 }
Example #22
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @return string
  */
 public function getViewLogIconHtml($listingProduct)
 {
     $listingProductId = (int) $listingProduct->getId();
     $connection = $this->resourceConnection->getConnection();
     // Get last messages
     // ---------------------------------------
     $dbSelect = $connection->select()->from($this->activeRecordFactory->getObject('Listing\\Log')->getResource()->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 = $connection->fetchAll($dbSelect);
     // ---------------------------------------
     // Get grouped messages by action_id
     // ---------------------------------------
     $actionsRows = array();
     $tempActionRows = array();
     $lastActionId = false;
     foreach ($logRows as $row) {
         $row['description'] = $this->getHelper('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\AbstractLog::TYPE_SUCCESS => 1, \Ess\M2ePro\Model\Log\AbstractLog::TYPE_ERROR => 2, \Ess\M2ePro\Model\Log\AbstractLog::TYPE_WARNING => 3);
             return $sortOrder[$a["type"]] > $sortOrder[$b["type"]];
         });
     }
     $tips = array(\Ess\M2ePro\Model\Log\AbstractLog::TYPE_SUCCESS => 'Last Action was completed successfully.', \Ess\M2ePro\Model\Log\AbstractLog::TYPE_ERROR => 'Last Action was completed with error(s).', \Ess\M2ePro\Model\Log\AbstractLog::TYPE_WARNING => 'Last Action was completed with warning(s).');
     $icons = array(\Ess\M2ePro\Model\Log\AbstractLog::TYPE_SUCCESS => 'normal', \Ess\M2ePro\Model\Log\AbstractLog::TYPE_ERROR => 'error', \Ess\M2ePro\Model\Log\AbstractLog::TYPE_WARNING => 'warning');
     $summary = $this->createBlock('Log\\Grid\\Summary', '', ['data' => ['entity_id' => (int) $listingProduct->getId(), 'rows' => $actionsRows, 'tips' => $tips, 'icons' => $icons, 'view_help_handler' => 'ListingProductVariationManageVariationsGridObj.viewItemHelp', 'hide_help_handler' => 'ListingProductVariationManageVariationsGridObj.hideItemHelp']]);
     return $summary->toHtml();
 }
Example #23
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @param \Ess\M2ePro\Model\Connector\Connection\Response\Message $message
  * @param int $priority
  */
 public function logListingProductMessage(\Ess\M2ePro\Model\Listing\Product $listingProduct, \Ess\M2ePro\Model\Connector\Connection\Response\Message $message, $priority = \Ess\M2ePro\Model\Log\AbstractLog::PRIORITY_MEDIUM)
 {
     if ($this->storeMode) {
         $this->storedMessages[] = array('type' => $this->initLogType($message), 'text' => $message->getText());
         return;
     }
     $this->getListingLog()->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), $this->initiator, $this->actionId, $this->action, $message->getText(), $this->initLogType($message), $priority);
 }
Example #24
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $childListingProduct
  * @return bool
  */
 public function tryToRemoveChildListingProduct(\Ess\M2ePro\Model\Listing\Product $childListingProduct)
 {
     if ($childListingProduct->isLocked()) {
         return false;
     }
     if ($childListingProduct->isStoppable()) {
         $this->modelFactory->getObject('StopQueue')->add($childListingProduct);
     }
     $this->getTypeModel()->removeChildListingProduct($childListingProduct->getId());
     return true;
 }
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @return \Ess\M2ePro\Model\Amazon\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\Amazon\Listing\Product\Action\Type\ListAction\Request */
         $request = $this->modelFactory->getObject('Amazon\\Listing\\Product\\Action\\Type\\ListAction\\Request');
         $request->setParams($this->params);
         $request->setListingProduct($listingProduct);
         $request->setConfigurator($listingProduct->getActionConfigurator());
         $request->setValidatorsData($this->getValidatorsData($listingProduct));
         $this->requestsObjects[$listingProduct->getId()] = $request;
     }
     return $this->requestsObjects[$listingProduct->getId()];
 }
Example #26
0
 /**
  * @param Product $listingProduct
  * @throws Logic
  */
 protected function logAddedToMagentoProduct(Product $listingProduct)
 {
     $tempLog = $this->activeRecordFactory->getObject('Listing\\Log');
     $tempLog->setComponentMode($this->getListing()->getComponentMode());
     $tempLog->addProductMessage($this->getListing()->getId(), $listingProduct->getProductId(), $listingProduct->getId(), \Ess\M2ePro\Helper\Data::INITIATOR_UNKNOWN, NULL, \Ess\M2ePro\Model\Listing\Log::ACTION_ADD_PRODUCT_TO_MAGENTO, 'Product was successfully Added', \Ess\M2ePro\Model\Log\AbstractLog::TYPE_NOTICE, \Ess\M2ePro\Model\Log\AbstractLog::PRIORITY_LOW);
 }
Example #27
0
 private function updateListingsProductChange(\Ess\M2ePro\Model\Listing\Product $listingProduct)
 {
     $this->activeRecordFactory->getObject('ProductChange')->addUpdateAction($listingProduct->getProductId(), \Ess\M2ePro\Model\ProductChange::INITIATOR_INSPECTOR);
     foreach ($listingProduct->getVariations(true) as $variation) {
         /** @var $variation \Ess\M2ePro\Model\Listing\Product\Variation */
         foreach ($variation->getOptions(true) as $option) {
             /** @var $option \Ess\M2ePro\Model\Listing\Product\Variation\Option */
             $this->activeRecordFactory->getObject('ProductChange')->addUpdateAction($option->getProductId(), \Ess\M2ePro\Model\ProductChange::INITIATOR_INSPECTOR);
         }
     }
 }
Example #28
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Product $listingProduct
  * @param array $data
  * @return \Ess\M2ePro\Model\Amazon\Listing\Product\Action\RequestData
  */
 protected function buildRequestDataObject(\Ess\M2ePro\Model\Listing\Product $listingProduct, array $data)
 {
     if (!isset($this->requestsDataObjects[$listingProduct->getId()])) {
         /** @var \Ess\M2ePro\Model\Amazon\Listing\Product\Action\RequestData $requestData */
         $requestData = $this->modelFactory->getObject('Amazon\\Listing\\Product\\Action\\RequestData');
         $requestData->setData($data);
         $requestData->setListingProduct($listingProduct);
         $this->requestsDataObjects[$listingProduct->getId()] = $requestData;
     }
     return $this->requestsDataObjects[$listingProduct->getId()];
 }
Example #29
0
 private function addNewVariations(\Ess\M2ePro\Model\Listing\Product $listingProduct, $addedVariations)
 {
     foreach ($addedVariations as $aVariation) {
         if (isset($aVariation['variation']['id'])) {
             $status = $aVariation['variation']['status'];
             $dataForUpdate = array('add' => $status == \Ess\M2ePro\Model\Listing\Product::STATUS_NOT_LISTED ? 1 : 0, 'delete' => 0);
             $this->ebayFactory->getObjectLoaded('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 = $this->ebayFactory->getObject('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']);
             $this->ebayFactory->getObject('Listing\\Product\\Variation\\Option')->addData($dataForAdd)->save();
         }
     }
 }
Example #30
0
 private function logListingProductMessage(\Ess\M2ePro\Model\Listing\Product $listingProduct, $action, $oldValue, $newValue, $messagePostfix = '')
 {
     // M2ePro\TRANSLATIONS
     // From [%from%] to [%to%].
     $log = $this->activeRecordFactory->getObject(ucfirst($listingProduct->getComponentMode()) . '\\Listing\\Log');
     $oldValue = strlen($oldValue) > 150 ? substr($oldValue, 0, 150) . ' ...' : $oldValue;
     $newValue = strlen($newValue) > 150 ? substr($newValue, 0, 150) . ' ...' : $newValue;
     $messagePostfix = trim(trim($messagePostfix), '.');
     if (!empty($messagePostfix)) {
         $messagePostfix = ' ' . $messagePostfix;
     }
     if ($listingProduct->isComponentModeEbay() && is_array($listingProduct->getData('found_options_ids'))) {
         $collection = $this->activeRecordFactory->getObject('Listing\\Product\\Variation\\Option')->getCollection()->addFieldToFilter('main_table.id', array('in' => $listingProduct->getData('found_options_ids')));
         $additionalData = array();
         foreach ($collection as $listingProductVariationOption) {
             /** @var \Ess\M2ePro\Model\Listing\Product\Variation\Option $listingProductVariationOption  */
             $additionalData['variation_options'][$listingProductVariationOption->getAttribute()] = $listingProductVariationOption->getOption();
         }
         if (!empty($additionalData['variation_options']) && $collection->getFirstItem()->getProductType() == \Ess\M2ePro\Model\Magento\Product::TYPE_BUNDLE) {
             foreach ($additionalData['variation_options'] as $attribute => $option) {
                 $log->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), \Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION, NULL, $action, $log->encodeDescription('From [%from%] to [%to%]' . $messagePostfix . '.', array('!from' => $oldValue, '!to' => $newValue)), \Ess\M2ePro\Model\Log\AbstractLog::TYPE_NOTICE, \Ess\M2ePro\Model\Log\AbstractLog::PRIORITY_LOW, array('variation_options' => array($attribute => $option)));
             }
             return;
         }
         $log->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), \Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION, NULL, $action, $log->encodeDescription('From [%from%] to [%to%]' . $messagePostfix . '.', array('!from' => $oldValue, '!to' => $newValue)), \Ess\M2ePro\Model\Log\AbstractLog::TYPE_NOTICE, \Ess\M2ePro\Model\Log\AbstractLog::PRIORITY_LOW, $additionalData);
         return;
     }
     $log->addProductMessage($listingProduct->getListingId(), $listingProduct->getProductId(), $listingProduct->getId(), \Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION, NULL, $action, $log->encodeDescription('From [%from%] to [%to%]' . $messagePostfix . '.', array('!from' => $oldValue, '!to' => $newValue)), \Ess\M2ePro\Model\Log\AbstractLog::TYPE_NOTICE, \Ess\M2ePro\Model\Log\AbstractLog::PRIORITY_LOW);
 }