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; }
private function addPriceProductChange(Ess_M2ePro_Model_ListingsProducts $listingProduct, $currentMethod, $ebayMethod, $sourceMethod) { $tempPrice = $listingProduct->{$currentMethod}(); if ($tempPrice != $listingProduct->{$ebayMethod}()) { $attribute = ''; $src = $listingProduct->getSellingFormatTemplate()->{$sourceMethod}(); if ($src['mode'] == Ess_M2ePro_Model_SellingFormatTemplates::PRICE_PRODUCT) { $attribute = 'price'; } if ($src['mode'] == Ess_M2ePro_Model_SellingFormatTemplates::PRICE_SPECIAL) { $attribute = 'special_price'; } if ($src['mode'] == Ess_M2ePro_Model_SellingFormatTemplates::PRICE_ATTRIBUTE) { $attribute = $src['attribute']; } $attribute != '' && $this->addProductChange($listingProduct->getProductId(), $attribute, $listingProduct->{$ebayMethod}(), $tempPrice); } }
protected function createNewEbayItemsId(Ess_M2ePro_Model_ListingsProducts $listingProduct, $ebayRealItemId) { $dataForAdd = array('item_id' => (double) $ebayRealItemId, 'product_id' => (int) $listingProduct->getProductId(), 'store_id' => (int) $listingProduct->getListing()->getStoreId()); return Mage::getModel('M2ePro/EbayItems')->setData($dataForAdd)->save()->getId(); }