public function process() { $this->setStatus(self::STATUS_SUCCESS); if (!$this->validateNeedRequestSend()) { return array(); } $this->updateOrLockListing(); $result = parent::process(); $this->checkUnlockListing(); return $result; }
protected function prepareResponseData($response) { if ($this->resultType != parent::MESSAGE_TYPE_ERROR) { $dataForUpdate = array('status' => Ess_M2ePro_Model_ListingsProducts::STATUS_STOPPED, 'ebay_end_date' => Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($response['ebay_end_date_raw'])); $this->ebayListing->addData($dataForUpdate)->save(); if ($response['already_stop']) { $message = array(parent::MESSAGE_TEXT_KEY => 'Item was already stopped on eBay', parent::MESSAGE_TYPE_KEY => parent::MESSAGE_TYPE_ERROR); $this->addProductsLogsMessage($this->ebayListing, $message, Ess_M2ePro_Model_ListingsLogs::PRIORITY_MEDIUM); } else { $message = array(parent::MESSAGE_TEXT_KEY => 'Item was successfully stopped', parent::MESSAGE_TYPE_KEY => parent::MESSAGE_TYPE_SUCCESS); $this->addProductsLogsMessage($this->ebayListing, $message, Ess_M2ePro_Model_ListingsLogs::PRIORITY_MEDIUM); } } return $response; }
protected function _migrateLastUpdateTime() { $dbSelect = $this->mySqlReadConnection->select()->from($this->_tableNameOldLastupdateTime, '*'); $updateTimeLast = $this->mySqlReadConnection->fetchAll($dbSelect); $stockLevelLastRun = isset($updateTimeLast[0]['check_time']) ? $updateTimeLast[0]['check_time'] : false; $orderLastRun = isset($updateTimeLast[1]['check_time']) ? $updateTimeLast[1]['check_time'] : false; if ($stockLevelLastRun) { $stockLevelLastRun = Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($stockLevelLastRun); Mage::helper('M2ePro/Module')->getConfig()->setGroupValue('/synchronization/settings/defaults/update_listings_products/', 'since_time', $stockLevelLastRun); } if ($orderLastRun) { $orderLastRun = Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($orderLastRun); Mage::helper('M2ePro/Module')->getConfig()->setGroupValue('/synchronization/settings/orders/', 'since_time', $orderLastRun); } }
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; } // Parser hack -> Mage::helper('M2ePro')->__('eBay Order status was not updated. Reason: %msg%'); $message = Mage::getSingleton('M2ePro/LogsBase')->encodeDescription('eBay Order status was not updated. Reason: %msg%', array('msg' => $message[parent::MESSAGE_TEXT_KEY])); $this->order->addErrorLogMessage($message); } return $result; }
public function process() { $this->setStatus(Ess_M2ePro_Model_Connectors_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_EbayListingsLogs::PRIORITY_MEDIUM; if ($message[parent::MESSAGE_TYPE_KEY] == parent::MESSAGE_TYPE_ERROR) { $priorityMessage = Ess_M2ePro_Model_EbayListingsLogs::PRIORITY_HIGH; } $this->addProductsLogsMessage($this->ebayListing, $message, $priorityMessage); } return $result; }
protected function prepareResponseData($response) { if ($this->resultType != parent::MESSAGE_TYPE_ERROR) { if ($response['already_active']) { $dataForUpdate = array('status' => Ess_M2ePro_Model_ListingsProducts::STATUS_LISTED, 'ebay_start_date' => Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($response['ebay_start_date_raw']), 'ebay_end_date' => Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($response['ebay_end_date_raw'])); $this->ebayListing->addData($dataForUpdate)->save(); $message = array(parent::MESSAGE_TEXT_KEY => 'Item already was started on eBay', parent::MESSAGE_TYPE_KEY => parent::MESSAGE_TYPE_ERROR); $this->addProductsLogsMessage($this->ebayListing, $message, Ess_M2ePro_Model_EbayListingsLogs::PRIORITY_MEDIUM); } else { $newEbayOldItems = $this->ebayListing->getData('ebay_old_items'); is_null($newEbayOldItems) && ($newEbayOldItems = ''); $newEbayOldItems != '' && ($newEbayOldItems .= ','); $newEbayOldItems .= $this->ebayListing->getData('ebay_item'); $dataForUpdate = array('ebay_item' => $response['ebay_item_id'], 'ebay_old_items' => $newEbayOldItems, 'ebay_qty_sold' => 0, 'ebay_bids' => 0, 'ebay_start_date' => Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($response['ebay_start_date_raw']), 'ebay_end_date' => Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($response['ebay_end_date_raw']), 'status' => Ess_M2ePro_Model_ListingsProducts::STATUS_LISTED); $this->ebayListing->addData($dataForUpdate)->save(); $message = array(parent::MESSAGE_TEXT_KEY => 'Item was successfully relisted', parent::MESSAGE_TYPE_KEY => parent::MESSAGE_TYPE_SUCCESS); $this->addProductsLogsMessage($this->ebayListing, $message, Ess_M2ePro_Model_EbayListingsLogs::PRIORITY_MEDIUM); } } return $response; }
private function prepareChangedListingsProducts(Ess_M2ePro_Model_ListingsProducts $tempListingProductModel, $ebayChange) { // Prepare ebay changes values //-------------------------- $tempEbayChanges = array(); if ($tempListingProductModel->isListingTypeAuction()) { $tempEbayChanges['ebay_start_price'] = (double) $ebayChange['currentPrice'] < 0 ? 0 : (double) $ebayChange['currentPrice']; } if ($tempListingProductModel->isListingTypeFixed()) { $tempEbayChanges['ebay_buyitnow_price'] = (double) $ebayChange['currentPrice'] < 0 ? 0 : (double) $ebayChange['currentPrice']; } $tempEbayChanges['ebay_qty'] = (int) $ebayChange['quantity'] < 0 ? 0 : (int) $ebayChange['quantity']; $tempEbayChanges['ebay_qty_sold'] = (int) $ebayChange['quantitySold'] < 0 ? 0 : (int) $ebayChange['quantitySold']; if ($tempListingProductModel->isListingTypeAuction()) { $tempEbayChanges['ebay_qty'] = 1; $tempEbayChanges['ebay_bids'] = (int) $ebayChange['bidCount'] < 0 ? 0 : (int) $ebayChange['bidCount']; } $tempEbayChanges['ebay_start_date'] = Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($ebayChange['startTime']); $tempEbayChanges['ebay_end_date'] = Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($ebayChange['endTime']); if (($ebayChange['listingStatus'] == self::EBAY_STATUS_COMPLETED || $ebayChange['listingStatus'] == self::EBAY_STATUS_ENDED) && $tempEbayChanges['ebay_qty'] == $tempEbayChanges['ebay_qty_sold']) { $tempEbayChanges['status'] = Ess_M2ePro_Model_ListingsProducts::STATUS_SOLD; } else { if ($ebayChange['listingStatus'] == self::EBAY_STATUS_COMPLETED) { $tempEbayChanges['status'] = Ess_M2ePro_Model_ListingsProducts::STATUS_STOPPED; } else { if ($ebayChange['listingStatus'] == self::EBAY_STATUS_ENDED) { $tempEbayChanges['status'] = Ess_M2ePro_Model_ListingsProducts::STATUS_FINISHED; } else { if ($ebayChange['listingStatus'] == self::EBAY_STATUS_ACTIVE) { $tempEbayChanges['status'] = Ess_M2ePro_Model_ListingsProducts::STATUS_LISTED; } } } } if ($tempEbayChanges['status'] != $tempListingProductModel->getStatus()) { $tempEbayChanges['status_changer'] = Ess_M2ePro_Model_ListingsProducts::STATUS_CHANGER_EBAY; Mage::getModel('M2ePro/ProductsChanges')->updateAttribute($tempListingProductModel->getProductId(), 'listing_product_status', 'listing_product_' . $tempListingProductModel->getId() . '_status_' . $tempListingProductModel->getStatus(), 'listing_product_' . $tempListingProductModel->getId() . '_status_' . $tempEbayChanges['status'], Ess_M2ePro_Model_ProductsChanges::CREATOR_TYPE_SYNCHRONIZATION); } //-------------------------- // 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->getListingsProductsVariations(true); if (count($tempVariations) == 0) { return $changedListingsProducts; } //----------------------- // Get listings products variations with options //----------------------- $tempVariationsWithOptions = array(); foreach ($tempVariations as $variation) { $options = $variation->getListingsProductsVariationsOptions(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['ebay_price'] = (double) $ebayVariation['price'] < 0 ? 0 : (double) $ebayVariation['price']; $tempEbayChanges['ebay_qty'] = (int) $ebayVariation['quantity'] < 0 ? 0 : (int) $ebayVariation['quantity']; $tempEbayChanges['ebay_qty_sold'] = (int) $ebayVariation['quantitySold'] < 0 ? 0 : (int) $ebayVariation['quantitySold']; if ($tempEbayChanges['ebay_qty'] <= $tempEbayChanges['ebay_qty_sold']) { $tempEbayChanges['status'] = Ess_M2ePro_Model_ListingsProducts::STATUS_SOLD; } if ($tempEbayChanges['ebay_qty'] <= 0) { $tempEbayChanges['status'] = Ess_M2ePro_Model_ListingsProducts::STATUS_NOT_LISTED; } //-------------------------- // Add changed variation //-------------------------- $changedListingsProducts['listings_products_variations'][] = array('instance' => $M2eProVariation, 'changes' => $tempEbayChanges); //-------------------------- break; } } //-------------------------- } return $changedListingsProducts; }
protected function updateProductAfterAction(Ess_M2ePro_Model_ListingsProducts $listingProduct, $ebayItemsId, $ebayStartDateRaw, $ebayEndDateRaw, $statusChanger, $saveEbayQtySold = false) { $dataForUpdate = array('ebay_items_id' => (int) $ebayItemsId, 'ebay_start_date' => Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($ebayStartDateRaw), 'ebay_end_date' => Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($ebayEndDateRaw), 'status' => Ess_M2ePro_Model_ListingsProducts::STATUS_LISTED, 'status_changer' => $statusChanger); if ($saveEbayQtySold) { $dataForUpdate['ebay_qty_sold'] = is_null($listingProduct->getEbayQtySold()) ? 0 : $listingProduct->getEbayQtySold(); $dataForUpdate['ebay_qty'] = $listingProduct->getQty() + $dataForUpdate['ebay_qty_sold']; } else { $dataForUpdate['ebay_qty_sold'] = 0; $dataForUpdate['ebay_qty'] = $listingProduct->getQty(); } if ($listingProduct->isListingTypeFixed()) { $dataForUpdate['ebay_start_price'] = NULL; $dataForUpdate['ebay_reserve_price'] = NULL; $dataForUpdate['ebay_buyitnow_price'] = $listingProduct->getBuyItNowPrice(); $dataForUpdate['ebay_bids'] = NULL; } else { $dataForUpdate['ebay_start_price'] = $listingProduct->getStartPrice(); $dataForUpdate['ebay_reserve_price'] = $listingProduct->getReservePrice(); $dataForUpdate['ebay_buyitnow_price'] = $listingProduct->getBuyItNowPrice(); $dataForUpdate['ebay_bids'] = 0; } $listingProduct->addData($dataForUpdate)->save(); }
protected function _getEbayCheckSinceTime() { $lastSinceTime = Mage::helper('M2ePro/Module')->getConfig()->getGroupValue($this->_configGroup, 'since_time'); if (is_null($lastSinceTime)) { $lastSinceTime = new DateTime(); $lastSinceTime->modify('-1 year'); } else { $lastSinceTime = new DateTime($lastSinceTime); } //------------------------ // Get min should for synch //------------------------ $minShouldTime = new DateTime(); $minShouldTime->modify('-1 month'); //------------------------ // Prepare last since time //------------------------ if ((int) $lastSinceTime->format('U') < (int) $minShouldTime->format('U')) { $lastSinceTime = new DateTime(); //if (Mage::helper('M2ePro/Module')->isInstalledM2eLastVersion()) { $lastSinceTime->modify('-1 hour'); //} else { // $lastSinceTime->modify("-10 days"); //} $this->_setEbayCheckSinceTime($lastSinceTime); } return Ess_M2ePro_Model_Connectors_Ebay_Abstract::ebayTimeToString($lastSinceTime); }