Ejemplo n.º 1
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Other $otherListing
  * @return \Ess\M2ePro\Model\Listing
  */
 public function getDefaultListing(\Ess\M2ePro\Model\Listing\Other $otherListing)
 {
     $accountId = $this->getAccount()->getId();
     if (isset($this->tempObjectsCache['listing_' . $accountId])) {
         return $this->tempObjectsCache['listing_' . $accountId];
     }
     $tempCollection = $this->amazonFactory->getObject('Listing')->getCollection();
     $tempCollection->addFieldToFilter('main_table.title', 'Default (' . $this->getAccount()->getTitle() . ' - ' . $this->getMarketplace()->getTitle() . ')');
     $tempItem = $tempCollection->getFirstItem();
     if (!is_null($tempItem->getId())) {
         $this->tempObjectsCache['listing_' . $accountId] = $tempItem;
         return $tempItem;
     }
     $tempModel = $this->amazonFactory->getObject('Listing');
     $dataForAdd = array('title' => 'Default (' . $this->getAccount()->getTitle() . ' - ' . $this->getMarketplace()->getTitle() . ')', 'store_id' => $otherListing->getChildObject()->getRelatedStoreId(), 'marketplace_id' => $this->getMarketplace()->getId(), 'account_id' => $accountId, 'template_selling_format_id' => $this->getDefaultSellingFormatTemplate($otherListing)->getId(), 'template_synchronization_id' => $this->getDefaultSynchronizationTemplate($otherListing)->getId(), 'source_products' => \Ess\M2ePro\Model\Listing::SOURCE_PRODUCTS_CUSTOM, 'sku_mode' => \Ess\M2ePro\Model\Amazon\Listing::SKU_MODE_DEFAULT, 'generate_sku_mode' => \Ess\M2ePro\Model\Amazon\Listing::GENERATE_SKU_MODE_NO, 'general_id_mode' => \Ess\M2ePro\Model\Amazon\Listing::GENERAL_ID_MODE_NOT_SET, 'worldwide_id_mode' => \Ess\M2ePro\Model\Amazon\Listing::WORLDWIDE_ID_MODE_NOT_SET, 'search_by_magento_title_mode' => \Ess\M2ePro\Model\Amazon\Listing::SEARCH_BY_MAGENTO_TITLE_MODE_NONE, 'handling_time_mode' => \Ess\M2ePro\Model\Amazon\Listing::HANDLING_TIME_MODE_NONE, 'restock_date_mode' => \Ess\M2ePro\Model\Amazon\Listing::RESTOCK_DATE_MODE_NONE, 'condition_mode' => \Ess\M2ePro\Model\Amazon\Listing::CONDITION_MODE_DEFAULT, 'condition_value' => \Ess\M2ePro\Model\Amazon\Listing::CONDITION_NEW, 'condition_note_mode' => \Ess\M2ePro\Model\Amazon\Listing::CONDITION_NOTE_MODE_NONE);
     $tempModel->addData($dataForAdd)->save();
     $childModel = $tempModel->getChildObject();
     $childModel->addData(array_merge([$tempModel->getResource()->getChildPrimary() => $tempModel->getId()], $dataForAdd))->save();
     $this->tempObjectsCache['listing_' . $accountId] = $tempModel;
     return $tempModel;
 }
Ejemplo n.º 2
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Other $otherListing
  * @return int|null
  * @throws \Ess\M2ePro\Model\Exception\Logic
  */
 protected function getTitleMappedMagentoProductId(\Ess\M2ePro\Model\Listing\Other $otherListing)
 {
     $temp = $otherListing->getChildObject()->getTitle();
     if (empty($temp)) {
         return NULL;
     }
     $attributeCode = NULL;
     if ($this->getAccount()->getChildObject()->isOtherListingsMappingTitleModeDefault()) {
         $attributeCode = 'name';
     }
     if ($this->getAccount()->getChildObject()->isOtherListingsMappingTitleModeCustomAttribute()) {
         $attributeCode = $this->getAccount()->getChildObject()->getOtherListingsMappingTitleAttribute();
     }
     if (is_null($attributeCode)) {
         return NULL;
     }
     $storeId = $otherListing->getChildObject()->getRelatedStoreId();
     $attributeValue = trim($otherListing->getChildObject()->getTitle());
     $productObj = $this->productFactory->create()->setStoreId($storeId);
     $productObj = $productObj->loadByAttribute($attributeCode, $attributeValue);
     if ($productObj && $productObj->getId()) {
         return $productObj->getId();
     }
     return NULL;
 }
Ejemplo n.º 3
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Other $listingOtherProduct
  * @param bool $checkingMode
  * @param bool $checkHasProduct
  * @return bool|\Ess\M2ePro\Model\Listing\Product
  * @throws \Ess\M2ePro\Model\Exception\Logic
  */
 public function addProductFromOther(\Ess\M2ePro\Model\Listing\Other $listingOtherProduct, $checkingMode = false, $checkHasProduct = true)
 {
     if (!$listingOtherProduct->getProductId()) {
         return false;
     }
     $productId = $listingOtherProduct->getProductId();
     $result = $this->getParentObject()->addProduct($productId, $checkingMode, true);
     if ($checkingMode) {
         return $result;
     }
     if (!$result instanceof \Ess\M2ePro\Model\Listing\Product) {
         return false;
     }
     $listingProduct = $result;
     $collection = $this->activeRecordFactory->getObject('Ebay\\Item')->getCollection()->addFieldToFilter('account_id', $listingOtherProduct->getAccount()->getId())->addFieldToFilter('item_id', $listingOtherProduct->getChildObject()->getItemId());
     $ebayItem = $collection->getLastItem();
     if (!$ebayItem->getId()) {
         $ebayItem->setData(array('account_id' => $listingOtherProduct->getAccount()->getId(), 'marketplace_id' => $listingOtherProduct->getMarketplace()->getId(), 'item_id' => $listingOtherProduct->getChildObject()->getItemId(), 'product_id' => $listingOtherProduct->getProductId()));
     }
     $ebayItem->setData('store_id', $this->getParentObject()->getStoreId())->save();
     $ebayListingProduct = $listingOtherProduct->getChildObject();
     $dataForUpdate = array('ebay_item_id' => $ebayItem->getId(), 'online_sku' => $ebayListingProduct->getSku(), 'online_title' => $ebayListingProduct->getTitle(), 'online_duration' => $ebayListingProduct->getOnlineDuration(), 'online_current_price' => $ebayListingProduct->getOnlinePrice(), 'online_qty' => $ebayListingProduct->getOnlineQty(), 'online_qty_sold' => $ebayListingProduct->getOnlineQtySold(), 'online_bids' => $ebayListingProduct->getOnlineBids(), 'start_date' => $ebayListingProduct->getStartDate(), 'end_date' => $ebayListingProduct->getEndDate(), 'status' => $listingOtherProduct->getStatus(), 'status_changer' => $listingOtherProduct->getStatusChanger());
     $listingOtherAdditionalData = $listingOtherProduct->getAdditionalData();
     if (!empty($listingOtherAdditionalData['out_of_stock_control'])) {
         $listingProductAdditionalData = $listingProduct->getAdditionalData();
         $additionalDataForUpdate = array_merge($listingProductAdditionalData, array('out_of_stock_control' => true));
         $dataForUpdate['additional_data'] = json_encode($additionalDataForUpdate);
     }
     $listingProduct->addData($dataForUpdate)->getChildObject()->addData($dataForUpdate);
     $listingProduct->save();
     return $listingProduct;
 }
Ejemplo n.º 4
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Other $otherListing
  * @return null|int
  * @throws \Ess\M2ePro\Model\Exception\Logic
  */
 protected function getTitleMappedMagentoProductId(\Ess\M2ePro\Model\Listing\Other $otherListing)
 {
     $temp = $otherListing->getChildObject()->getTitle();
     if (empty($temp)) {
         return NULL;
     }
     $attributeCode = NULL;
     if ($this->getAccount()->getChildObject()->isOtherListingsMappingTitleModeDefault()) {
         $attributeCode = 'name';
     }
     if ($this->getAccount()->getChildObject()->isOtherListingsMappingTitleModeCustomAttribute()) {
         $attributeCode = $this->getAccount()->getChildObject()->getOtherListingsMappingTitleAttribute();
     }
     if (is_null($attributeCode)) {
         return NULL;
     }
     $storeId = $otherListing->getChildObject()->getRelatedStoreId();
     $attributeValue = trim($otherListing->getChildObject()->getTitle());
     $productObj = $this->productFactory->create()->setStoreId($storeId);
     $productObj = $productObj->loadByAttribute($attributeCode, $attributeValue);
     if ($productObj && $productObj->getId()) {
         return $productObj->getId();
     }
     $findCount = preg_match('/^.+(\\[(.+)\\])$/', $attributeValue, $tempMatches);
     if ($findCount > 0 && isset($tempMatches[1])) {
         $attributeValue = trim(str_replace($tempMatches[1], '', $attributeValue));
         $productObj = $this->productFactory->create()->setStoreId($storeId);
         $productObj = $productObj->loadByAttribute($attributeCode, $attributeValue);
         if ($productObj && $productObj->getId()) {
             return $productObj->getId();
         }
     }
     return NULL;
 }
Ejemplo n.º 5
0
 /**
  * @param \Ess\M2ePro\Model\Listing\Other $listingOtherProduct
  * @param bool $checkingMode
  * @param bool $checkHasProduct
  * @return bool|\Ess\M2ePro\Model\Listing\Product
  * @throws \Ess\M2ePro\Model\Exception\Logic
  */
 public function addProductFromOther(\Ess\M2ePro\Model\Listing\Other $listingOtherProduct, $checkingMode = false, $checkHasProduct = true)
 {
     if (!$listingOtherProduct->getProductId()) {
         return false;
     }
     $productId = $listingOtherProduct->getProductId();
     $result = $this->getParentObject()->addProduct($productId, $checkingMode, $checkHasProduct);
     if ($checkingMode) {
         return $result;
     }
     if (!$result instanceof \Ess\M2ePro\Model\Listing\Product) {
         return false;
     }
     $listingProduct = $result;
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Product $amazonListingProduct */
     $amazonListingProduct = $listingProduct->getChildObject();
     $variationManager = $amazonListingProduct->getVariationManager();
     if ($variationManager->isRelationParentType()) {
         $variationManager->switchModeToAnother();
     }
     $amazonListingProduct->getAmazonItem()->setData('store_id', $this->getParentObject()->getStoreId())->save();
     /** @var \Ess\M2ePro\Model\Amazon\Listing\Other $amazonListingOther */
     $amazonListingOther = $listingOtherProduct->getChildObject();
     $dataForUpdate = array('general_id' => $amazonListingOther->getGeneralId(), 'sku' => $amazonListingOther->getSku(), 'online_price' => $amazonListingOther->getOnlinePrice(), 'online_qty' => $amazonListingOther->getOnlineQty(), 'is_afn_channel' => (int) $amazonListingOther->isAfnChannel(), 'is_isbn_general_id' => (int) $amazonListingOther->isIsbnGeneralId(), 'status' => $listingOtherProduct->getStatus(), 'status_changer' => $listingOtherProduct->getStatusChanger());
     $listingProduct->addData($dataForUpdate);
     $amazonListingProduct->addData($dataForUpdate);
     $listingProduct->save();
     if ($amazonListingOther->isRepricing()) {
         $listingProductRepricing = $this->activeRecordFactory->getObject('Amazon\\Listing\\Product\\Repricing');
         $listingProductRepricing->setData(array('listing_product_id' => $listingProduct->getId(), 'is_online_disabled' => $amazonListingOther->isRepricingDisabled()));
         $listingProductRepricing->save();
     }
     return $listingProduct;
 }