public function process() { $this->setStatus(self::STATUS_SUCCESS); if (!$this->validateNeedRequestSend()) { return array(); } $this->updateOrLockListing(); $result = parent::process(); $this->checkUnlockListing(); return $result; }
protected function getRequestInfo() { if (isset($this->cache['request_info'])) { return $this->cache['request_info']; } if (!isset($this->params['__request_info__']) || !is_array($this->params['__request_info__']) || count($this->params['__request_info__']) <= 0) { $this->cache['request_info'] = parent::getRequestInfo(); } else { $this->cache['request_info'] = $this->params['__request_info__']; unset($this->params['__request_info__']); } return $this->cache['request_info']; }
public function process() { if (!$this->validateNeedRequestSend()) { return false; } $result = parent::process(); foreach ($this->messages as $message) { if ($message[parent::MESSAGE_TYPE_KEY] != parent::MESSAGE_TYPE_ERROR) { continue; } $this->order->addErrorLog('eBay Order status was not updated. Reason: %msg%', array('msg' => $message[parent::MESSAGE_TEXT_KEY])); } return $result; }
public function process() { if (!$this->validateNeedRequestSend()) { return false; } $result = parent::process(); foreach ($this->messages as $message) { if ($message[parent::MESSAGE_TYPE_KEY] != parent::MESSAGE_TYPE_ERROR) { continue; } $message = 'Shipping status was not updated (Item: %item_id%, Transaction: %trn_id%). Reason: %msg%'; $this->orderItem->getOrder()->addErrorLog($message, array('!item_id' => $this->orderItem->getChildObject()->getItemId(), '!trn_id' => $this->orderItem->getChildObject()->getTransactionId(), 'msg' => $message[parent::MESSAGE_TEXT_KEY])); } return $result; }
public function process() { if (!$this->validateNeedRequestSend()) { return false; } $result = parent::process(); foreach ($this->messages as $message) { if ($message[parent::MESSAGE_TYPE_KEY] != parent::MESSAGE_TYPE_ERROR) { continue; } $this->orderItem->getOrder()->addErrorLog('Unpaid Item Process was not open for item #%id%. Reason: %msg%', array('!id' => $this->orderItem->getChildObject()->getItemId(), 'msg' => $message[parent::MESSAGE_TEXT_KEY])); if (isset($message[parent::MESSAGE_CODE_KEY]) && in_array($message[parent::MESSAGE_CODE_KEY], array(16207, 16212))) { $this->orderItem->setData('unpaid_item_process_state', Ess_M2ePro_Model_Ebay_Order_Item::UNPAID_ITEM_PROCESS_OPENED); $this->orderItem->save(); } } return $result; }
public function process() { $this->setStatus(Ess_M2ePro_Model_Connector_Server_Ebay_Item_Abstract::STATUS_SUCCESS); if (!$this->validateNeedRequestSend()) { return array(); } $this->updateOrLockListing(); $result = parent::process(); $this->checkUnlockListing(); foreach ($this->messages as $message) { $priorityMessage = Ess_M2ePro_Model_Log_Abstract::PRIORITY_MEDIUM; if ($message[parent::MESSAGE_TYPE_KEY] == parent::MESSAGE_TYPE_ERROR) { $priorityMessage = Ess_M2ePro_Model_Log_Abstract::PRIORITY_HIGH; } $this->addProductsLogsMessage($this->otherListing, $message, $priorityMessage); } return $result; }
protected function updateProductAfterAction(Ess_M2ePro_Model_Listing_Product $listingProduct, array $nativeRequestData = array(), array $params = array(), $ebayItemsId = NULL, $saveEbayQtySold = false) { $dataForUpdate = array('status' => Ess_M2ePro_Model_Listing_Product::STATUS_LISTED); !is_null($ebayItemsId) && ($dataForUpdate['ebay_item_id'] = (int) $ebayItemsId); isset($params['status_changer']) && ($dataForUpdate['status_changer'] = (int) $params['status_changer']); if (isset($params['start_date_raw'])) { $dataForUpdate['start_date'] = Ess_M2ePro_Model_Connector_Server_Ebay_Abstract::ebayTimeToString($params['start_date_raw']); } if (isset($params['end_date_raw'])) { $dataForUpdate['end_date'] = Ess_M2ePro_Model_Connector_Server_Ebay_Abstract::ebayTimeToString($params['end_date_raw']); } if ($saveEbayQtySold) { $dataForUpdate['online_qty_sold'] = is_null($listingProduct->getChildObject()->getOnlineQtySold()) ? 0 : $listingProduct->getChildObject()->getOnlineQtySold(); $tempIsVariation = $nativeRequestData['is_variation_item'] && isset($nativeRequestData['variation']); $tempUpdateFlag = $tempIsVariation || isset($nativeRequestData['qty']); if ($tempUpdateFlag) { $tempQty = $tempIsVariation ? $listingProduct->getChildObject()->getQty() : $nativeRequestData['qty']; $dataForUpdate['online_qty'] = (int) $tempQty + (int) $dataForUpdate['online_qty_sold']; } } else { $dataForUpdate['online_qty_sold'] = 0; $tempIsVariation = $nativeRequestData['is_variation_item'] && isset($nativeRequestData['variation']); $tempUpdateFlag = $tempIsVariation || isset($nativeRequestData['qty']); if ($tempUpdateFlag) { $tempQty = $tempIsVariation ? $listingProduct->getChildObject()->getQty() : $nativeRequestData['qty']; $dataForUpdate['online_qty'] = $tempQty; } } if ($listingProduct->getChildObject()->isListingTypeFixed()) { $dataForUpdate['online_start_price'] = NULL; $dataForUpdate['online_reserve_price'] = NULL; $dataForUpdate['online_bids'] = NULL; $tempIsVariation = $nativeRequestData['is_variation_item'] && isset($nativeRequestData['variation']); $tempUpdateFlag = $tempIsVariation || isset($nativeRequestData['price_fixed']); if ($tempUpdateFlag) { if ($tempIsVariation) { $tempPrice = NULL; foreach ($nativeRequestData['variation'] as $variation) { if ((int) $variation['qty'] <= 0) { continue; } if (!is_null($tempPrice) && (double) $variation['price'] >= $tempPrice) { continue; } $tempPrice = (double) $variation['price']; } } else { $tempPrice = $nativeRequestData['price_fixed']; } $dataForUpdate['online_buyitnow_price'] = (double) $tempPrice; } } else { $dataForUpdate['online_bids'] = 0; if (isset($nativeRequestData['price_start'])) { $dataForUpdate['online_start_price'] = (double) $nativeRequestData['price_start']; } if (isset($nativeRequestData['price_reserve'])) { $dataForUpdate['online_reserve_price'] = (double) $nativeRequestData['price_reserve']; } if (isset($nativeRequestData['price_buyitnow'])) { $dataForUpdate['online_buyitnow_price'] = (double) $nativeRequestData['price_buyitnow']; } } $listingProduct->addData($dataForUpdate)->save(); }
protected function updateProductAfterAction(Ess_M2ePro_Model_Listing_Other $listingOther, array $nativeRequestData = array(), array $params = array(), $ebayItemId = NULL, $saveEbayQtySold = false) { $dataForUpdate = array('status' => Ess_M2ePro_Model_Listing_Product::STATUS_LISTED); !is_null($ebayItemId) && ($dataForUpdate['item_id'] = $ebayItemId); isset($params['status_changer']) && ($dataForUpdate['status_changer'] = (int) $params['status_changer']); if (isset($params['start_date_raw'])) { $dataForUpdate['start_date'] = Ess_M2ePro_Model_Connector_Server_Ebay_Abstract::ebayTimeToString($params['start_date_raw']); } if (isset($params['end_date_raw'])) { $dataForUpdate['end_date'] = Ess_M2ePro_Model_Connector_Server_Ebay_Abstract::ebayTimeToString($params['end_date_raw']); } if (isset($nativeRequestData['title'])) { $dataForUpdate['title'] = $nativeRequestData['title']; } if ($saveEbayQtySold) { $dataForUpdate['online_qty_sold'] = is_null($listingOther->getChildObject()->getOnlineQtySold()) ? 0 : $listingOther->getChildObject()->getOnlineQtySold(); if (isset($nativeRequestData['qty'])) { $dataForUpdate['online_qty'] = (int) $nativeRequestData['qty'] + (int) $dataForUpdate['online_qty_sold']; } } else { $dataForUpdate['online_qty_sold'] = 0; if (isset($nativeRequestData['qty'])) { $dataForUpdate['online_qty'] = (int) $nativeRequestData['qty']; } } if (isset($nativeRequestData['price_fixed'])) { $dataForUpdate['online_price'] = (double) $nativeRequestData['price_fixed']; } $listingOther->addData($dataForUpdate)->save(); }
private function prepareSinceTime($sinceTime) { if (is_null($sinceTime)) { $sinceTime = new DateTime('now', new DateTimeZone('UTC')); $sinceTime->modify('-10 days'); } else { $sinceTime = new DateTime($sinceTime, new DateTimeZone('UTC')); } return Ess_M2ePro_Model_Connector_Server_Ebay_Abstract::ebayTimeToString($sinceTime); }
protected function updateProductAfterAction(Ess_M2ePro_Model_Listing_Product $listingProduct, array $nativeRequestData = array(), array $params = array(), $ebayItemsId = NULL, $saveSoldData = false) { $dataForUpdate = array('status' => Ess_M2ePro_Model_Listing_Product::STATUS_LISTED, 'additional_data' => $listingProduct->getAdditionalData()); !empty($nativeRequestData['title']) && ($dataForUpdate['online_title'] = $nativeRequestData['title']); !empty($nativeRequestData['sku']) && ($dataForUpdate['online_sku'] = $nativeRequestData['sku']); $dataForUpdate['additional_data']['is_eps_ebay_images_mode'] = $params['is_eps_ebay_images_mode']; $isImagesUploadError = isset($params['is_images_upload_error']) ? $params['is_images_upload_error'] : false; if (isset($nativeRequestData['images']['images']) && !$isImagesUploadError) { $dataForUpdate['additional_data']['ebay_product_images_hash'] = sha1(json_encode($nativeRequestData['images']['images'])); } !is_null($ebayItemsId) && ($dataForUpdate['ebay_item_id'] = (int) $ebayItemsId); isset($params['status_changer']) && ($dataForUpdate['status_changer'] = (int) $params['status_changer']); if (isset($nativeRequestData['category_main_id'])) { $dataForUpdate['online_category'] = Mage::helper('M2ePro/Component_Ebay_Category_Ebay')->getPath($nativeRequestData['category_main_id'], $listingProduct->getMarketplace()->getId()) . ' (' . $nativeRequestData['category_main_id'] . ')'; } if (isset($params['start_date_raw'])) { $dataForUpdate['start_date'] = Ess_M2ePro_Model_Connector_Server_Ebay_Abstract::ebayTimeToString($params['start_date_raw']); } if (isset($params['end_date_raw'])) { $dataForUpdate['end_date'] = Ess_M2ePro_Model_Connector_Server_Ebay_Abstract::ebayTimeToString($params['end_date_raw']); } if ($saveSoldData) { $dataForUpdate['online_qty_sold'] = is_null($listingProduct->getChildObject()->getOnlineQtySold()) ? 0 : $listingProduct->getChildObject()->getOnlineQtySold(); $tempIsVariation = $nativeRequestData['is_variation_item'] && isset($nativeRequestData['variation']); $tempUpdateFlag = $tempIsVariation || isset($nativeRequestData['qty']); if ($tempUpdateFlag) { $tempQty = $tempIsVariation ? $listingProduct->getChildObject()->getQty() : $nativeRequestData['qty']; $dataForUpdate['online_qty'] = (int) $tempQty + (int) $dataForUpdate['online_qty_sold']; } } else { $dataForUpdate['online_qty_sold'] = 0; $tempIsVariation = $nativeRequestData['is_variation_item'] && isset($nativeRequestData['variation']); $tempUpdateFlag = $tempIsVariation || isset($nativeRequestData['qty']); if ($tempUpdateFlag) { $tempQty = $tempIsVariation ? $listingProduct->getChildObject()->getQty() : $nativeRequestData['qty']; $dataForUpdate['online_qty'] = $tempQty; } } if ($listingProduct->getChildObject()->isListingTypeFixed()) { $dataForUpdate['online_start_price'] = NULL; $dataForUpdate['online_reserve_price'] = NULL; $dataForUpdate['online_bids'] = NULL; $tempIsVariation = $nativeRequestData['is_variation_item'] && isset($nativeRequestData['variation']); $tempUpdateFlag = $tempIsVariation || isset($nativeRequestData['price_fixed']); if ($tempUpdateFlag) { if ($tempIsVariation) { $tempPrice = NULL; foreach ($nativeRequestData['variation'] as $variation) { if ((int) $variation['qty'] <= 0) { continue; } if (!is_null($tempPrice) && (double) $variation['price'] >= $tempPrice) { continue; } $tempPrice = (double) $variation['price']; } } else { $tempPrice = $nativeRequestData['price_fixed']; } $dataForUpdate['online_buyitnow_price'] = (double) $tempPrice; } } else { !$saveSoldData && ($dataForUpdate['online_bids'] = 0); if (isset($nativeRequestData['price_start'])) { $dataForUpdate['online_start_price'] = (double) $nativeRequestData['price_start']; } if (isset($nativeRequestData['price_reserve'])) { $dataForUpdate['online_reserve_price'] = (double) $nativeRequestData['price_reserve']; } if (isset($nativeRequestData['price_buyitnow'])) { $dataForUpdate['online_buyitnow_price'] = (double) $nativeRequestData['price_buyitnow']; } } $dataForUpdate['additional_data'] = json_encode($dataForUpdate['additional_data']); $listingProduct->addData($dataForUpdate)->save(); }
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_Server_Ebay_Abstract::ebayTimeToString($ebayChange['startTime']); $tempEbayChanges['end_date'] = Ess_M2ePro_Model_Connector_Server_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 ($tempEbayChanges['status'] != $tempListingProductModel->getStatus()) { $tempEbayChanges['status_changer'] = Ess_M2ePro_Model_Listing_Product::STATUS_CHANGER_COMPONENT; Mage::getModel('M2ePro/ProductChange')->updateAttribute($tempListingProductModel->getProductId(), 'ebay_listing_product_status', 'listing_product_id_' . $tempListingProductModel->getId() . '_status_' . $tempListingProductModel->getStatus(), 'listing_product_id_' . $tempListingProductModel->getId() . '_status_' . $tempEbayChanges['status'], Ess_M2ePro_Model_ProductChange::CREATOR_TYPE_SYNCHRONIZATION); $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; }