private function getProductDatesChanges(Ess_M2ePro_Model_Listing_Product $listingProduct, array $change)
 {
     return array('start_date' => Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($change['startTime']), 'end_date' => Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($change['endTime']));
 }
Example #2
0
 protected function appendStartDateEndDateValues($data, $response)
 {
     if (isset($response['ebay_start_date_raw'])) {
         $data['start_date'] = Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($response['ebay_start_date_raw']);
     }
     if (isset($response['ebay_end_date_raw'])) {
         $data['end_date'] = Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($response['ebay_end_date_raw']);
     }
     return $data;
 }
 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;
 }
Example #4
0
 private function prepareFromTime(Ess_M2ePro_Model_Account $account)
 {
     $lastSynchronizationDate = $account->getData('orders_last_synchronization');
     if (is_null($lastSynchronizationDate)) {
         $sinceTime = new DateTime('now', new DateTimeZone('UTC'));
         $sinceTime = Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($sinceTime);
         $this->saveLastUpdateTime($account, $sinceTime);
         return $sinceTime;
     }
     $sinceTime = new DateTime($lastSynchronizationDate, new DateTimeZone('UTC'));
     // Get min date for synch
     //------------------------
     $minDate = new DateTime('now', new DateTimeZone('UTC'));
     $minDate->modify('-90 days');
     //------------------------
     // Prepare last date
     //------------------------
     if ((int) $sinceTime->format('U') < (int) $minDate->format('U')) {
         $sinceTime = $minDate;
     }
     //------------------------
     return Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($sinceTime);
 }
Example #5
0
 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_Ebay_Abstract::ebayTimeToString($sinceTime);
 }
Example #6
0
 private function prepareFromTime(Ess_M2ePro_Model_Account $account)
 {
     $lastSynchronizationDate = $account->getData('orders_last_synchronization');
     if (is_null($lastSynchronizationDate)) {
         $sinceTime = new DateTime('now', new DateTimeZone('UTC'));
         $sinceTime = Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($sinceTime);
         $this->saveLastUpdateTime($account, $sinceTime);
         return $sinceTime;
     }
     $sinceTime = new DateTime($lastSynchronizationDate, new DateTimeZone('UTC'));
     return Ess_M2ePro_Model_Connector_Ebay_Abstract::ebayTimeToString($sinceTime);
 }