* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 1.4 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ // Loading eBay Class Request if (file_exists(dirname(__FILE__).'/eBayRequest.php')) require_once(dirname(__FILE__).'/eBayRequest.php'); // Checking compatibility with older PrestaShop and fixing it if (!defined('_MYSQL_ENGINE_')) define('_MYSQL_ENGINE_', 'MyISAM'); class Ebay extends Module { private $_html = ''; private $_postErrors = array(); private $_shippingMethod = array(); private $_webserviceTestResult = ''; private $_webserviceError = ''; private $_fieldsList = array(); private $_moduleName = 'ebay'; private $id_lang; /******************************************************************/ /** Construct Method **********************************************/ /******************************************************************/ public function __construct() { global $cookie; $this->name = 'ebay'; $this->tab = 'market_place'; $this->version = '1.1'; parent::__construct (); $this->displayName = $this->l('eBay'); $this->description = $this->l('Open your shop on the eBay market place !'); $this->id_lang = Language::getIdByIso('fr'); // Check the country and ask the bypass if not 'fr' if (strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))) != 'fr' && !isset($cookie->ebay_country_default_fr)) { $this->warning = $this->l('eBay module currently works only for eBay.fr'); return false; } // Checking Extension if (!extension_loaded('curl') || !ini_get('allow_url_fopen')) { if (!extension_loaded('curl') && !ini_get('allow_url_fopen')) $this->warning = $this->l('You must enable cURL extension and allow_url_fopen option on your server if you want to use this module.'); elseif (!extension_loaded('curl')) $this->warning = $this->l('You must enable cURL extension on your server if you want to use this module.'); elseif (!ini_get('allow_url_fopen')) $this->warning = $this->l('You must enable allow_url_fopen option on your server if you want to use this module.'); return false; } // Checking compatibility with older PrestaShop and fixing it if (!Configuration::get('PS_SHOP_DOMAIN')) Configuration::updateValue('PS_SHOP_DOMAIN', $_SERVER['HTTP_HOST']); // Generate eBay Security Token if not exists if (!Configuration::get('EBAY_SECURITY_TOKEN')) Configuration::updateValue('EBAY_SECURITY_TOKEN', Tools::passwdGen(30)); // Check if installed if (self::isInstalled($this->name)) { // Generate warnings if (!Configuration::get('EBAY_API_TOKEN')) $this->warning = $this->l('You must register your module on eBay.'); // Shipping methods $this->_shippingMethod = array( 7104 => array('description' => 'Colissimo', 'shippingService' => 'FR_ColiposteColissimo', 'shippingServiceID' => '7104'), 7112 => array('description' => 'Ecopli', 'shippingService' => 'FR_Ecopli', 'shippingServiceID' => '7112'), 57104 => array('description' => 'La Poste - Courrier International Prioritaire', 'shippingService' => 'FR_LaPosteInternationalPriorityCourier', 'shippingServiceID' => '57104'), 7101 => array('description' => 'Lettre', 'shippingService' => 'FR_PostOfficeLetter', 'shippingServiceID' => '7101'), 57105 => array('description' => 'La Poste - Courrier International Economique', 'shippingService' => 'FR_LaPosteInternationalEconomyCourier', 'shippingServiceID' => '57105'), 57106 => array('description' => 'La Poste - Colissimo International', 'shippingService' => 'FR_LaPosteColissimoInternational', 'shippingServiceID' => '57106'), 7102 => array('description' => 'Lettre avec suivi', 'shippingService' => 'FR_PostOfficeLetterFollowed', 'shippingServiceID' => '7102'), 57107 => array('description' => 'La Poste - Colis Economique International', 'shippingService' => 'FR_LaPosteColisEconomiqueInternational', 'shippingServiceID' => '57107'), 7103 => array('description' => 'Lettre recommandée', 'shippingService' => 'FR_PostOfficeLetterRecommended', 'shippingServiceID' => '7103'), 7121 => array('description' => 'Lettre Max', 'shippingService' => 'FR_LaPosteLetterMax', 'shippingServiceID' => '7121'), 7113 => array('description' => 'Coliéco', 'shippingService' => 'FR_Colieco', 'shippingServiceID' => '7113'), 57108 => array('description' => 'La Poste - Colissimo Emballage International', 'shippingService' => 'FR_LaPosteColissimoEmballageInternational', 'shippingServiceID' => '57108'), 57114 => array('description' => 'Chronopost Express International', 'shippingService' => 'FR_ChronopostExpressInternational', 'shippingServiceID' => '57114'), 7106 => array('description' => 'Colissimo Recommandé', 'shippingService' => 'FR_ColiposteColissimoRecommended', 'shippingServiceID' => '7106'), 57109 => array('description' => 'Chronopost Classic International', 'shippingService' => 'FR_ChronopostClassicInternational', 'shippingServiceID' => '57109'), 57110 => array('description' => 'Chronopost Premium International', 'shippingService' => 'FR_ChronopostPremiumInternational', 'shippingServiceID' => '57110'), 7117 => array('description' => 'Chronopost - Chrono Relais', 'shippingService' => 'FR_ChronopostChronoRelais', 'shippingServiceID' => '7117'), 57111 => array('description' => 'UPS Standard', 'shippingService' => 'FR_UPSStandardInternational', 'shippingServiceID' => '57111'), 7111 => array('description' => 'Autre mode d\'envoi de courrier', 'shippingService' => 'FR_Autre', 'shippingServiceID' => '7111'), 57112 => array('description' => 'UPS Express', 'shippingService' => 'FR_UPSExpressInternational', 'shippingServiceID' => '57112'), 7114 => array('description' => 'Autre mode d\'envoi de colis', 'shippingService' => 'FR_AuteModeDenvoiDeColis', 'shippingServiceID' => '7114'), 57113 => array('description' => 'DHL', 'shippingService' => 'FR_DHLInternational', 'shippingServiceID' => '57113'), 57101 => array('description' => 'Frais de livraison internationale fixes', 'shippingService' => 'FR_StandardInternational', 'shippingServiceID' => '57101'), 7116 => array('description' => 'Chronopost', 'shippingService' => 'FR_Chronopost', 'shippingServiceID' => '7116'), 57102 => array('description' => 'Frais fixes pour livraison internationale express', 'shippingService' => 'FR_ExpeditedInternational', 'shippingServiceID' => '57102'), 57103 => array('description' => 'Autres livraisons internationales (voir description)', 'shippingService' => 'FR_OtherInternational', 'shippingServiceID' => '57103'), 7118 => array('description' => 'Chrono 10', 'shippingService' => 'FR_Chrono10', 'shippingServiceID' => '7118'), 7119 => array('description' => 'Chrono 13', 'shippingService' => 'FR_Chrono13', 'shippingServiceID' => '7119'), 7120 => array('description' => 'Chrono 18', 'shippingService' => 'FR_Chrono18', 'shippingServiceID' => '7120'), 7105 => array('description' => 'Coliposte - Colissimo Direct', 'shippingService' => 'FR_ColiposteColissimoDirect', 'shippingServiceID' => '7105'), 7107 => array('description' => 'Chronoposte - Chrono Classic International', 'shippingService' => 'FR_ChronoposteInternationalClassic', 'shippingServiceID' => '7107'), 7108 => array('description' => 'DHL - Express Europack', 'shippingService' => 'FR_DHLExpressEuropack', 'shippingServiceID' => '7108'), 7109 => array('description' => 'UPS - Standard', 'shippingService' => 'FR_UPSStandard', 'shippingServiceID' => '7109'), ); } } /******************************************************************/ /** Install / Uninstall Methods ***********************************/ /******************************************************************/ public function install() { global $cookie; // Install SQL include(dirname(__FILE__).'/sql-install.php'); foreach ($sql as $s) if (!Db::getInstance()->Execute($s)) return false; // Install Module if (!parent::install() || !$this->registerHook('addproduct') || !$this->registerHook('updateproduct') || !$this->registerHook('updateProductAttribute') || !$this->registerHook('deleteproduct') || !$this->registerHook('newOrder') || !$this->registerHook('backOfficeTop') || !$this->registerHook('backOfficeFooter') || !$this->registerHook('header') || !$this->registerHook('updateOrderStatus')) return false; // Generate Product Template $content = file_get_contents(dirname(__FILE__).'/template/ebay.tpl'); $content = str_replace('{SHOP_NAME}', Configuration::get('PS_SHOP_NAME'), $content); $content = str_replace('{SHOP_URL}', 'http://'.Configuration::get('PS_SHOP_DOMAIN').'/'.__PS_BASE_URI__.'/', $content); $content = str_replace('{MODULE_URL}', 'http://'.Configuration::get('PS_SHOP_DOMAIN').'/'.__PS_BASE_URI__.'/modules/ebay/', $content); Configuration::updateValue('EBAY_PRODUCT_TEMPLATE', ''); Configuration::updateValue('EBAY_PRODUCT_TEMPLATE', $content, true); // Init Configuration::updateValue('EBAY_VERSION', $this->version); return true; } public function uninstall() { global $cookie; // Uninstall Config foreach ($this->_fieldsList as $keyConfiguration => $name) if (!Configuration::deleteByName($keyConfiguration)) return false; // Uninstall SQL include(dirname(__FILE__).'/sql-uninstall.php'); foreach ($sql as $s) if (!Db::getInstance()->Execute($s)) return false; Configuration::deleteByName('EBAY_API_SESSION'); Configuration::deleteByName('EBAY_API_USERNAME'); Configuration::deleteByName('EBAY_API_TOKEN'); Configuration::deleteByName('EBAY_IDENTIFIER'); Configuration::deleteByName('EBAY_SHOP'); Configuration::deleteByName('EBAY_PAYPAL_EMAIL'); Configuration::deleteByName('EBAY_SHIPPING_CARRIER_ID'); Configuration::deleteByName('EBAY_SHIPPING_COST'); Configuration::deleteByName('EBAY_SHIPPING_COST_CURRENCY'); Configuration::deleteByName('EBAY_SHOP_POSTALCODE'); Configuration::deleteByName('EBAY_CATEGORY_LOADED'); Configuration::deleteByName('EBAY_CATEGORY_LOADED_DATE'); Configuration::deleteByName('EBAY_PRODUCT_TEMPLATE'); Configuration::deleteByName('EBAY_SYNC_MODE'); Configuration::deleteByName('EBAY_ORDER_LAST_UPDATE'); Configuration::deleteByName('EBAY_VERSION'); Configuration::deleteByName('EBAY_SECURITY_TOKEN'); // Uninstall Module if (!parent::uninstall() || !$this->unregisterHook('addproduct') || !$this->unregisterHook('updateproduct') || !$this->unregisterHook('updateProductAttribute') || !$this->unregisterHook('deleteproduct') || !$this->unregisterHook('newOrder') || !$this->unregisterHook('backOfficeTop') || !$this->unregisterHook('backOfficeFooter') || !$this->unregisterHook('header') || !$this->unregisterHook('updateOrderStatus')) return false; // Clean Cookie $cookie->eBaySession = ''; $cookie->eBayUsername = ''; return true; } /******************************************************************/ /** Hook Methods **************************************************/ /******************************************************************/ public function hookNewOrder($params) { if ((int)$params['cart']->id < 1) return false; $sql = '`id_product` IN (SELECT `id_product` FROM `'._DB_PREFIX_.'cart_product` WHERE `id_cart` = '.(int)$params['cart']->id.')'; if (Configuration::get('EBAY_SYNC_MODE') == 'A') { // Retrieve product list for eBay (which have matched categories) AND Send each product on eBay $productsList = Db::getInstance()->ExecuteS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE '.$sql.' AND `active` = 1 AND `id_category_default` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_category` > 0 AND `id_ebay_category` > 0)'); if ($productsList) $this->_syncProducts($productsList); } elseif (Configuration::get('EBAY_SYNC_MODE') == 'B') { // Select the sync Categories and Retrieve product list for eBay (which have matched and sync categories) AND Send each product on eBay $productsList = Db::getInstance()->ExecuteS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE '.$sql.' AND `active` = 1 AND `id_category_default` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_category` > 0 AND `id_ebay_category` > 0 AND `sync` = 1)'); if ($productsList) $this->_syncProducts($productsList); } } public function hookaddproduct($params) { if (!isset($params['product']->id)) return false; $id_product = $params['product']->id; if ((int)$id_product < 1) return false; if (Configuration::get('EBAY_SYNC_MODE') == 'A') { // Retrieve product list for eBay (which have matched categories) AND Send each product on eBay $productsList = Db::getInstance()->ExecuteS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `id_product` = '.(int)$id_product.' AND `active` = 1 AND `id_category_default` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_category` > 0 AND `id_ebay_category` > 0)'); if ($productsList) $this->_syncProducts($productsList); } elseif (Configuration::get('EBAY_SYNC_MODE') == 'B') { // Select the sync Categories and Retrieve product list for eBay (which have matched and sync categories) AND Send each product on eBay $productsList = Db::getInstance()->ExecuteS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `id_product` = '.(int)$id_product.' AND `active` = 1 AND `id_category_default` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_category` > 0 AND `id_ebay_category` > 0 AND `sync` = 1)'); if ($productsList) $this->_syncProducts($productsList); } } public function hookbackOfficeTop($params) { // Check if the module is configured if (!Configuration::get('EBAY_PAYPAL_EMAIL')) return false; // If no update yet if (!Configuration::get('EBAY_ORDER_LAST_UPDATE')) Configuration::updateValue('EBAY_ORDER_LAST_UPDATE', date('Y-m-d').'T'.date('H:i:s').'.000Z'); // init Var $dateNew = date('Y-m-d').'T'.date('H:i:s').'.000Z'; if (Configuration::get('EBAY_ORDER_LAST_UPDATE') < date('Y-m-d', strtotime('-45 minutes')).'T'.date('H:i:s', strtotime('-45 minutes')).'.000Z') { $ebay = new eBayRequest(); $orderList = $ebay->getOrders(Configuration::get('EBAY_ORDER_LAST_UPDATE'), $dateNew); if ($orderList) foreach ($orderList as $order) if ($order['status'] == 'Complete'&& isset($order['product_list']) && count($order['product_list'])) { $result = Db::getInstance()->getRow('SELECT `id_customer` FROM `'._DB_PREFIX_.'customer` WHERE `active` = 1 AND `email` = \''.pSQL($order['email']).'\' AND `deleted` = 0'.(substr(_PS_VERSION_, 0, 3) == '1.3' ? '' : ' AND `is_guest` = 0')); $id_customer = (isset($result['id_customer']) ? $result['id_customer'] : 0); // Add customer if he doesn't exist if ($id_customer < 1) { $customer = new Customer(); $customer->id_gender = 9; $customer->id_default_group = 1; $customer->secure_key = md5(uniqid(rand(), true)); $customer->email = $order['email']; $customer->passwd = md5(pSQL(_COOKIE_KEY_.rand())); $customer->last_passwd_gen = pSQL(date('Y-m-d H:i:s')); $customer->newsletter = 0; $customer->lastname = pSQL($order['familyname']); $customer->firstname = pSQL($order['firstname']); $customer->active = 1; $customer->add(); $id_customer = $customer->id; } $address = new Address(); $address->id_customer = (int)$id_customer; $address->id_country = (int)Country::getByIso($order['country_iso_code']); $address->alias = 'eBay '.date('Y-m-d H:i:s'); $address->lastname = pSQL($order['familyname']); $address->firstname = pSQL($order['firstname']); $address->address1 = pSQL($order['address1']); $address->address2 = pSQL($order['address2']); $address->postcode = pSQL($order['postalcode']); $address->city = pSQL($order['city']); $address->phone = pSQL($order['phone']); $address->active = 1; $address->add(); $id_address = $address->id; $flag = 1; foreach ($order['product_list'] as $product) { if ((int)$product['id_product'] < 1 || !Db::getInstance()->getValue('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `id_product` = '.(int)$product['id_product'])) $flag = 0; if (isset($product['id_product_attribute']) && !Db::getInstance()->getValue('SELECT `id_product_attribute` FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.(int)$product['id_product'].' AND `id_product_attribute` = '.(int)$product['id_product_attribute'])) $flag = 0; } if ($flag == 1) { $cartAdd = new Cart(); $cartAdd->id_customer = $id_customer; $cartAdd->id_address_invoice = $id_address; $cartAdd->id_address_delivery = $id_address; $cartAdd->id_carrier = 1; $cartAdd->id_lang = $this->id_lang; $cartAdd->id_currency = Currency::getIdByIsoCode('EUR'); $cartAdd->add(); foreach ($order['product_list'] as $product) $cartAdd->updateQty((int)($product['quantity']), (int)($product['id_product']), (isset($product['id_product_attribute']) ? $product['id_product_attribute'] : NULL)); $cartAdd->update(); // Fix on sending e-mail Db::getInstance()->autoExecute(_DB_PREFIX_.'customer', array('email' => 'NOSEND-EBAY'), 'UPDATE', '`id_customer` = '.(int)$id_customer); $customerClear = new Customer(); if (method_exists($customerClear, 'clearCache')) $customerClear->clearCache(true); // Validate order $paiement = new eBayPayment(); $paiement->validateOrder(intval($cartAdd->id), Configuration::get('PS_OS_PAYMENT'), floatval($cartAdd->getOrderTotal(true, 3)), 'Paypal eBay', NULL, array(), intval($cartAdd->id_currency)); $id_order = $paiement->currentOrder; // Fix on sending e-mail Db::getInstance()->autoExecute(_DB_PREFIX_.'customer', array('email' => pSQL($order['email'])), 'UPDATE', '`id_customer` = '.(int)$id_customer); // Update price (because of possibility of price impact) $updateOrder = array( 'total_paid' => floatval($order['amount']), 'total_paid_real' => floatval($order['amount']), 'total_products' => floatval($order['amount']), 'total_products_wt' => floatval($order['amount']), 'total_shipping' => floatval($order['shippingServiceCost']), ); Db::getInstance()->autoExecute(_DB_PREFIX_.'orders', $updateOrder, 'UPDATE', '`id_order` = '.(int)$id_order); foreach ($order['product_list'] as $product) Db::getInstance()->autoExecute(_DB_PREFIX_.'order_detail', array('product_price' => floatval($product['price']), 'tax_rate' => 0, 'reduction_percent' => 0), 'UPDATE', '`id_order` = '.(int)$id_order.' AND `product_id` = '.(int)$product['id_product'].' AND `product_attribute_id` = '.(int)$product['id_product_attribute']); } } Configuration::updateValue('EBAY_ORDER_LAST_UPDATE', $dateNew); } } public function hookupdateOrderStatus($params) { } // Alias public function hookupdateproduct($params) { $this->hookaddproduct($params); } public function hookupdateProductAttribute($params) { $this->hookaddproduct($params); } public function hookdeleteproduct($params) { $this->hookaddproduct($params); } public function hookheader($params) { $this->hookbackOfficeTop($params); } public function hookbackOfficeFooter($params) { $this->hookbackOfficeTop($params); } /******************************************************************/ /** Main Form Methods *********************************************/ /******************************************************************/ public function getContent() { global $cookie; $this->_html .= '

' . $this->l('eBay').'

'; // Checking Country if (Tools::getValue('ebay_country_default_fr') == 'ok') $cookie->ebay_country_default_fr = true; if (strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))) != 'fr' && !isset($cookie->ebay_country_default_fr)) return $this->_html.$this->displayError($this->l('eBay module currently works only for eBay.fr').'. '.$this->l('Continue anyway ?').''); // Checking Extension if (!extension_loaded('curl') || !ini_get('allow_url_fopen')) { if (!extension_loaded('curl') && !ini_get('allow_url_fopen')) return $this->_html.$this->displayError($this->l('You must enable cURL extension and allow_url_fopen option on your server if you want to use this module.')); elseif (!extension_loaded('curl')) return $this->_html.$this->displayError($this->l('You must enable cURL extension on your server if you want to use this module.')); elseif (!ini_get('allow_url_fopen')) return $this->_html.$this->displayError($this->l('You must enable allow_url_fopen option on your server if you want to use this module.')); } // If isset Post Var, post process else display form if (!empty($_POST) AND Tools::isSubmit('submitSave')) { $this->_postValidation(); if (!sizeof($this->_postErrors)) $this->_postProcess(); else foreach ($this->_postErrors AS $err) $this->_html .= '
nok '.$err.'
'; } $this->_displayForm(); return $this->_html; } private function _displayForm() { // Test alert $alert = array(); if (!Configuration::get('EBAY_API_TOKEN')) $alert['registration'] = 1; if (!ini_get('allow_url_fopen')) $alert['allowurlfopen'] = 1; if (!extension_loaded('curl')) $alert['curl'] = 1; // Displaying Information from Prestashop $context = stream_context_create(array('http' => array('method'=>"GET", 'timeout' => 5))); $prestashopContent = @file_get_contents('http://www.prestashop.com/partner/modules/ebay.php?version='.$this->version.'&shop='.urlencode(Configuration::get('PS_SHOP_NAME')).'®istered='.($alert['registration'] == 1 ? 'no' : 'yes').'&url='.urlencode($_SERVER['HTTP_HOST']).'&iso_country='.$isoCountry.'&iso_lang='.Tools::strtolower($isoUser).'&id_lang='.(int)$cookie->id_lang.'&email='.urlencode(Configuration::get('PS_SHOP_EMAIL')).'&security='.md5(Configuration::get('PS_SHOP_EMAIL')._COOKIE_IV_), false, $context); // Displaying page $this->_html .= '
'.$this->l('eBay Module Status').''; $this->_html .= '
'; if (!count($alert)) $this->_html .= ''.$this->l('eBay Module is configured and online!').''; else { $this->_html .= ''.$this->l('eBay Module is not configured yet, you must:').''; $this->_html .= '
'.(isset($alert['registration']) ? '' : '').' 1) '.$this->l('Register the module on eBay'); $this->_html .= '
'.(isset($alert['allowurlfopen']) ? '' : '').' 2) '.$this->l('Allow url fopen'); $this->_html .= '
'.(isset($alert['curl']) ? '' : '').' 3) '.$this->l('Enable cURL'); } $this->_html .= '
'.$prestashopContent.'
'; $this->_html .= '
 
'; if (!Configuration::get('EBAY_API_TOKEN')) $this->_html .= $this->_displayFormRegister(); else $this->_html .= $this->_displayFormConfig(); } private function _postValidation() { if (!Configuration::get('EBAY_API_TOKEN')) $this->_postValidationRegister(); elseif (Tools::getValue('section') == 'parameters') $this->_postValidationParameters(); elseif (Tools::getValue('section') == 'category') $this->_postValidationCategory(); elseif (Tools::getValue('section') == 'template') $this->_postValidationTemplateManager(); elseif (Tools::getValue('section') == 'sync') $this->_postValidationEbaySync(); } private function _postProcess() { if (!Configuration::get('EBAY_API_TOKEN')) $this->_postProcessRegister(); elseif (Tools::getValue('section') == 'parameters') $this->_postProcessParameters(); elseif (Tools::getValue('section') == 'category') $this->_postProcessCategory(); elseif (Tools::getValue('section') == 'template') $this->_postProcessTemplateManager(); elseif (Tools::getValue('section') == 'sync') $this->_postProcessEbaySync(); } /******************************************************************/ /** Register Form Config Methods **********************************/ /******************************************************************/ private function _displayFormRegister() { global $cookie; $ebay = new eBayRequest(); if (!empty($cookie->eBaySession) && isset($_GET['action']) && $_GET['action'] == 'logged') { if (isset($_POST['eBayUsername'])) { $cookie->eBayUsername = $_POST['eBayUsername']; Configuration::updateValue('EBAY_API_USERNAME', $_POST['eBayUsername']); } $ebay->session = $cookie->eBaySession; $ebay->username = $cookie->eBayUsername; $html = ' '; $html .= '
'.$this->l('Register the module on eBay').''; $html .= '

'.$this->l('Loading').'

'; $html .= '

'.$this->l('Once you sign in from the new eBay window, the module will automatically finish the installation a few seconds later').'

'; $html .= '
'; } else { if (empty($cookie->eBaySession)) { $ebay->login(); $cookie->eBaySession = $ebay->session; Configuration::updateValue('EBAY_API_SESSION', $ebay->session); } $html = '
'.$this->l('Register the module on eBay').'



'; } return $html; } private function _postValidationRegister() { } private function _postProcessRegister() { } /******************************************************************/ /** Parameters Form Config Methods ********************************/ /******************************************************************/ private function _displayFormConfig() { $html = '


'; if (isset($_GET['id_tab'])) $html .= ''; return $html; } private function _displayFormParameters() { global $cookie; // Loading config currency $configCurrency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT'))); // Display Form $html = '

'.$this->l('To export your products on eBay, you have to create a pro account on eBay (see Help) and configure your eBay-Prestashop module.').'

'.(Configuration::get('EBAY_IDENTIFIER') ? ''.$this->l('Your products on eBay').'' : $this->l('Your eBay identifier')).'

'.(Configuration::get('EBAY_SHOP') ? ''.$this->l('Your shop on eBay').'' : $this->l('Your eBay shop name')).'

'.$this->l('You have to set your PayPal e-mail account, it\'s the only payment available with this module').'

'.$this->l('Shipping cost configuration for your products on eBay').'

'.$configCurrency->sign.'

'.$this->l('Shipping cost configuration for your products on eBay').'

'.$this->l('Your shop\'s postal code').'

'; if (!Configuration::get('EBAY_CATEGORY_LOADED')) { $html .= ' '; } return $html; } private function _postValidationParameters() { // Check configuration values if (Tools::getValue('ebay_identifier') == NULL) $this->_postErrors[] = $this->l('Your eBay identifier account is not specified or is invalid'); if (Tools::getValue('ebay_paypal_email') == NULL OR !Validate::isEmail(Tools::getValue('ebay_paypal_email'))) $this->_postErrors[] = $this->l('Your Paypal E-mail account is not specified or is invalid'); if (Tools::getValue('ebay_shipping_cost') == '' OR !is_numeric(Tools::getValue('ebay_shipping_cost'))) $this->_postErrors[] = $this->l('Your shipping cost is not specified or is invalid'); if (Tools::getValue('ebay_shop_postalcode') == '' OR !Validate::isPostCode(Tools::getValue('ebay_shop_postalcode'))) $this->_postErrors[] = $this->l('Your shop\'s postal code is not specified or is invalid'); } private function _postProcessParameters() { // Saving new configurations if (Configuration::updateValue('EBAY_PAYPAL_EMAIL', pSQL(Tools::getValue('ebay_paypal_email'))) && Configuration::updateValue('EBAY_IDENTIFIER', pSQL(Tools::getValue('ebay_identifier'))) && Configuration::updateValue('EBAY_SHOP', pSQL(Tools::getValue('ebay_shop'))) && Configuration::updateValue('EBAY_SHIPPING_COST', (float)(Tools::getValue('ebay_shipping_cost'))) && Configuration::updateValue('EBAY_SHIPPING_COST_CURRENCY', (int)(Configuration::get('PS_CURRENCY_DEFAULT'))) && Configuration::updateValue('EBAY_SHIPPING_CARRIER_ID', pSQL(Tools::getValue('ebay_shipping_carrier_id'))) && Configuration::updateValue('EBAY_SHOP_POSTALCODE', pSQL(Tools::getValue('ebay_shop_postalcode')))) $this->_html .= $this->displayConfirmation($this->l('Settings updated')); else $this->_html .= $this->displayError($this->l('Settings failed')); } /******************************************************************/ /** Category Form Config Methods **********************************/ /******************************************************************/ private function _getChildCategories($categories, $id, $path = array(), $pathAdd = '') { $categoryTmp = array(); $categoryTab = array(); if ($pathAdd != '') $path[] = $pathAdd; if (isset($categories[$id])) foreach ($categories[$id] as $idc => $cc) { $name = ''; if ($path) foreach ($path as $p) $name .= $p.' > '; $name .= $cc['infos']['name']; $categoryTab[] = array('id_category' => $cc['infos']['id_category'], 'name' => $name); $categoryTmp = $this->_getChildCategories($categories, $idc, $path, $cc['infos']['name']); $categoryTab = array_merge($categoryTab, $categoryTmp); } return $categoryTab; } private function _displayFormCategory() { global $cookie; // Check if the module is configured if (!Configuration::get('EBAY_PAYPAL_EMAIL')) return '

'.$this->l('You have to configure "General Settings" tab before using this tab.').'


'; // Display eBay Categories if (!Configuration::get('EBAY_CATEGORY_LOADED')) { $ebay = new eBayRequest(); $ebay->saveCategories(); Configuration::updateValue('EBAY_CATEGORY_LOADED', 1); Configuration::updateValue('EBAY_CATEGORY_LOADED_DATE', date('Y-m-d H:i:s')); } // Loading categories $categoryConfigList = array(); $categoryConfigListTmp = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'ebay_category_configuration`'); foreach ($categoryConfigListTmp as $c) $categoryConfigList[$c['id_category']] = $c; $categoryList = $this->_getChildCategories(Category::getCategories($cookie->id_lang), 0); $eBayCategoryList = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'ebay_category` WHERE `id_category_ref` = `id_category_ref_parent`'); // Display header $html = '

'.$this->l('To export your products on eBay, you have to associate each one of your shop categories to an eBay category. You can also define an impact of your price on eBay.').'


'.$this->l('You can use the button below to associate automatically the categories which have no association for the moment with an eBay suggested category.').'


'; // Displaying categories if (!$categoryList) $html .= ''; foreach ($categoryList as $k => $c) { // Display line $alt = 0; if ($k % 2 != 0) $alt = ' class="alt_row"'; $html .= ' '; } $html .= '
'.$this->l('Category').' '.$this->l('eBay Category').' '.$this->l('Price impact').'
'.$this->l('No category found.').'
'.$c['name'].' '; if (isset($categoryConfigList[$c['id_category']])) $html .= ''; $html .= '

'.$this->l('Beware : Only product default categories are used for this configuration.').'


* Certaines catégories bénéficient du nouveau format d’annonces multi-versions qui permet de publier 1 seule annonce pour plusieurs versions du même produit.
Pour les catégories ne bénéficiant pas de ce format multi-versions, une annonce sera créée pour chaque version du produit.
Cliquez ici pour plus d’informations sur les catégories multi-versions



'; return $html; } private function _postValidationCategory() { } private function _postProcessCategory() { // Init Var global $cookie; $date = date('Y-m-d H:i:s'); $services = Tools::getValue('service'); if (Tools::getValue('action') == 'suggestCategories') { // Loading categories $ebay = new eBayRequest(); $categoryConfigList = array(); $categoryConfigListTmp = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'ebay_category_configuration`'); foreach ($categoryConfigListTmp as $c) $categoryConfigList[$c['id_category']] = $c; $categoryList = Db::getInstance()->ExecuteS('SELECT `id_category`, `name` FROM `'._DB_PREFIX_.'category_lang` WHERE `id_lang` = '.(int)$this->id_lang); foreach ($categoryList as $k => $c) if (!isset($categoryConfigList[$c['id_category']])) { $productTest = Db::getInstance()->getRow(' SELECT pl.`name`, pl.`description` FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$this->id_lang.') WHERE `id_category_default` = '.(int)$c['id_category']); $id_category_ref_suggested = $ebay->getSuggestedCategories($c['name'].' '.$productTest['name']); $id_ebay_category_suggested = Db::getInstance()->getValue('SELECT `id_ebay_category` FROM `'._DB_PREFIX_.'ebay_category` WHERE `id_category_ref` = '.(int)$id_category_ref_suggested); if ((int)$id_ebay_category_suggested > 0) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_category_configuration', array('id_country' => 8, 'id_ebay_category' => (int)$id_ebay_category_suggested, 'id_category' => (int)$c['id_category'], 'percent' => 0, 'date_add' => pSQL($date), 'date_upd' => pSQL($date)), 'INSERT'); } $this->_html .= $this->displayConfirmation($this->l('Settings updated')); return true; } // Sort post datas $postValue = array(); foreach ($_POST as $k => $v) { if (strlen($k) > 8 && substr($k, 0, 8) == 'category') $postValue[substr($k, 8, strlen($k) - 8)]['id_ebay_category'] = $v; if (strlen($k) > 7 && substr($k, 0, 7) == 'percent') $postValue[substr($k, 7, strlen($k) - 7)]['percent'] = $v; } // Insert and update configuration foreach ($postValue as $id_category => $tab) { $arraySQL = array(); $date = date('Y-m-d H:i:s'); if ($tab['id_ebay_category']) $arraySQL = array('id_country' => 8, 'id_ebay_category' => (int)$tab['id_ebay_category'], 'id_category' => (int)$id_category, 'percent' => pSQL($tab['percent']), 'date_upd' => pSQL($date)); $id_ebay_category_configuration = Db::getInstance()->getValue('SELECT `id_ebay_category_configuration` FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_category` = '.(int)$id_category); if ($id_ebay_category_configuration > 0) { if ($arraySQL) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_category_configuration', $arraySQL, 'UPDATE', '`id_category` = '.(int)$id_category); else Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_category` = '.(int)$id_category); } elseif ($arraySQL) { $arraySQL['date_add'] = $date; Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_category_configuration', $arraySQL, 'INSERT'); } } $this->_html .= $this->displayConfirmation($this->l('Settings updated')); } /******************************************************************/ /** Template Manager Form Config Methods **************************/ /******************************************************************/ private function _displayFormTemplateManager() { global $cookie; // Check if the module is configured if (!Configuration::get('EBAY_PAYPAL_EMAIL')) return '

'.$this->l('You have to configure "General Settings" tab before using this tab.').'


'; $iso = Language::getIsoById((int)($cookie->id_lang)); $isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en'); $ad = dirname($_SERVER["PHP_SELF"]); // Display Form $html = '

'.$this->l('You can customise the template for your products page on eBay').' :


'.(substr(_PS_VERSION_, 0, 3) == '1.3' ? ' ' : ' ').'
'; return $html; } private function _postValidationTemplateManager() { } private function _postProcessTemplateManager() { // Saving new configurations if (Configuration::updateValue('EBAY_PRODUCT_TEMPLATE', Tools::getValue('ebay_product_template'), true)) $this->_html .= $this->displayConfirmation($this->l('Settings updated')); else $this->_html .= $this->displayError($this->l('Settings failed')); } /******************************************************************/ /** Ebay Sync Form Config Methods **************************/ /******************************************************************/ private function _displayFormEbaySync() { global $cookie; // Check if the module is configured if (!Configuration::get('EBAY_PAYPAL_EMAIL')) return '

'.$this->l('You have to configure "General Settings" tab before using this tab.').'


'; if (Db::getInstance()->getValue('SELECT COUNT(`id_ebay_category_configuration`) as nb FROM `'._DB_PREFIX_.'ebay_category_configuration`') < 1) return '

'.$this->l('You have to configure "Categories Settings" tab before using this tab.').'


'; $nbProductsModeA = Db::getInstance()->getValue(' SELECT COUNT(`id_product`) as nb FROM `'._DB_PREFIX_.'product` WHERE `id_category_default` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_ebay_category` > 0)'); $nbProductsModeB = Db::getInstance()->getValue(' SELECT COUNT(`id_product`) as nb FROM `'._DB_PREFIX_.'product` WHERE `id_category_default` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_ebay_category` > 0 AND `sync` = 1)'); $nbProducts = $nbProductsModeA; if (Configuration::get('EBAY_SYNC_MODE') == 'B') $nbProducts = $nbProductsModeB; // Display Form $html = '

'.$this->l('You will now push your products on eBay.').' '.$this->l('Reminder,').' '.$this->l('you will not have to pay any fees if you have a shop on eBay.').'




'.$this->l('Option A').' : '.$this->l('Sync all your products with eBay').'
'.$this->l('Option B').' : '.$this->l('Sync the products only from selected categories').'



'.$this->l('When update a product, resync only price and quantity').'
l('products').')" OnClick="return confirm(\''.$this->l('You will push').' \' + nbProducts + \' '.$this->l('products on eBay. Do you want to confirm ?').'\');" type="submit">

'.$this->l('Beware ! If some of your categories are not multi sku compliant, some of your products may create more than one product on eBay.').'

'; return $html; } private function _postValidationEbaySync() { } private function _postProcessEbaySync() { // Update Sync Option Configuration::updateValue('EBAY_SYNC_OPTION_RESYNC', (Tools::getValue('ebay_sync_option_resync') == 1 ? 1 : 0)); if ($_POST['ebay_sync_mode'] == 'A') { // Update Sync Mod Configuration::updateValue('EBAY_SYNC_MODE', 'A'); // Retrieve product list for eBay (which have matched categories) $productsList = Db::getInstance()->ExecuteS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `active` = 1 AND `id_category_default` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_category` > 0 AND `id_ebay_category` > 0)'); // Send each product on eBay $this->_syncProducts($productsList); } else { // Update Sync Mod Configuration::updateValue('EBAY_SYNC_MODE', 'B'); // Select the sync Categories and Retrieve product list for eBay (which have matched and sync categories) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_category_configuration', array('sync' => 0), 'UPDATE', ''); foreach ($_POST['category'] as $id_category) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_category_configuration', array('sync' => 1), 'UPDATE', '`id_category` = '.(int)$id_category); $productsList = Db::getInstance()->ExecuteS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `active` = 1 AND `id_category_default` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_category` > 0 AND `id_ebay_category` > 0 AND `sync` = 1)'); // Send each product on eBay $this->_syncProducts($productsList); } } private function _syncProducts($productsList) { global $link; $fees = 0; $count = 0; $count_success = 0; $count_error = 0; $tab_error = array(); $date = date('Y-m-d H:i:s'); $ebay = new eBayRequest(); $categoryDefaultCache = array(); // Up the time limit @set_time_limit(3600); // Run the products list foreach ($productsList as $product) { // Product instanciation $product = new Product((int)$product['id_product'], true, $this->id_lang); if (Validate::isLoadedObject($product) && $product->id_category_default > 0) { // Load default category matched in cache if (!isset($categoryDefaultCache[$product->id_category_default])) $categoryDefaultCache[$product->id_category_default] = Db::getInstance()->getRow('SELECT ec.`id_category_ref`, ec.`is_multi_sku`, ecc.`percent` FROM `'._DB_PREFIX_.'ebay_category` ec LEFT JOIN `'._DB_PREFIX_.'ebay_category_configuration` ecc ON (ecc.`id_ebay_category` = ec.`id_ebay_category`) WHERE ecc.`id_category` = '.(int)$product->id_category_default); // Load Pictures $pictures = array(); $picturesMedium = array(); $picturesLarge = array(); $prefix = (substr(_PS_VERSION_, 0, 3) == '1.3' ? 'http://'.Configuration::get('PS_SHOP_DOMAIN').'/' : ''); $images = $product->getImages($this->id_lang); foreach ($images as $image) { $pictures[] = $prefix.$link->getImageLink('', $product->id.'-'.$image['id_image'], NULL); $picturesMedium[] = $prefix.$link->getImageLink('', $product->id.'-'.$image['id_image'], 'medium'); $picturesLarge[] = $prefix.$link->getImageLink('', $product->id.'-'.$image['id_image'], 'large'); } // Load Variations $variations = array(); $variationsList = array(); $combinations = $product->getAttributeCombinaisons($this->id_lang); if (isset($combinations)) foreach ($combinations as $c) { $variationsList[$c['group_name']][$c['attribute_name']] = 1; $variations[$c['id_product'].'-'.$c['id_product_attribute']]['id_attribute'] = $c['id_product_attribute']; $variations[$c['id_product'].'-'.$c['id_product_attribute']]['quantity'] = $c['quantity']; $variations[$c['id_product'].'-'.$c['id_product_attribute']]['variations'][] = array('name' => $c['group_name'], 'value' => $c['attribute_name']); $variations[$c['id_product'].'-'.$c['id_product_attribute']]['price_static'] = Product::getPriceStatic((int)$c['id_product'], true, (int)$c['id_product_attribute']); $price = $variations[$c['id_product'].'-'.$c['id_product_attribute']]['price_static']; $price_original = $price; if ($categoryDefaultCache[$product->id_category_default]['percent'] > 0) $price *= (1 + ($categoryDefaultCache[$product->id_category_default]['percent'] / 100)); elseif ($categoryDefaultCache[$product->id_category_default]['percent'] < 0) $price *= (1 - ($categoryDefaultCache[$product->id_category_default]['percent'] / (-100))); $variations[$c['id_product'].'-'.$c['id_product_attribute']]['price'] = round($price, 2); if ($categoryDefaultCache[$product->id_category_default]['percent'] < 0) { $variations[$c['id_product'].'-'.$c['id_product_attribute']]['price_original'] = round($price_original, 2); $variations[$c['id_product'].'-'.$c['id_product_attribute']]['price_percent'] = round($categoryDefaultCache[$product->id_category_default]['percent']); } } // Load Variations Pictures $combinationsImages = $product->getCombinationImages(2); if (isset($combinationsImages) && !empty($combinationsImages) && count($combinationsImages) > 0) foreach ($combinationsImages as $ci) foreach ($ci as $i) $variations[$product->id.'-'.$i['id_product_attribute']]['pictures'][] = $prefix.$link->getImageLink('', $product->id.'-'.$i['id_image'], NULL); // Load basic price $price = Product::getPriceStatic((int)$product->id, true); $price_original = $price; if ($categoryDefaultCache[$product->id_category_default]['percent'] > 0) $price *= (1 + ($categoryDefaultCache[$product->id_category_default]['percent'] / 100)); elseif ($categoryDefaultCache[$product->id_category_default]['percent'] < 0) $price *= (1 - ($categoryDefaultCache[$product->id_category_default]['percent'] / (-100))); $price = round($price, 2); // Generate array and try insert in database $datas = array( 'id_product' => $product->id, 'name' => str_replace('&', '&', $product->name), 'brand' => $product->manufacturer_name, 'description' => $product->description, 'price' => $price, 'quantity' => $product->quantity, 'categoryId' => $categoryDefaultCache[$product->id_category_default]['id_category_ref'], 'shippingService' => $this->_shippingMethod[Configuration::get('EBAY_SHIPPING_CARRIER_ID')]['shippingService'], 'shippingCost' => Configuration::get('EBAY_SHIPPING_COST'), 'variationsList' => $variationsList, 'variations' => $variations, 'pictures' => $pictures, 'picturesMedium' => $picturesMedium, 'picturesLarge' => $picturesLarge, ); // Save percent and price discount if ($categoryDefaultCache[$product->id_category_default]['percent'] < 0) { $datas['price_original'] = round($price_original, 2); $datas['price_percent'] = round($categoryDefaultCache[$product->id_category_default]['percent']); } // Load eBay Description $datas['description'] = str_replace( array('{DESCRIPTION}', '{EBAY_IDENTIFIER}', '{EBAY_SHOP}', '{SLOGAN}', '{PRODUCT_NAME}'), array($datas['description'], Configuration::get('EBAY_IDENTIFIER'), Configuration::get('EBAY_SHOP'), '', $product->name), Configuration::get('EBAY_PRODUCT_TEMPLATE') ); // Export on eBay if (count($datas['variations']) > 0) { // Variations Case if ($categoryDefaultCache[$product->id_category_default]['is_multi_sku'] == 1) { // Load eBay Description $datas['description'] = str_replace( array('{MAIN_IMAGE}', '{MEDIUM_IMAGE_1}', '{MEDIUM_IMAGE_2}', '{MEDIUM_IMAGE_3}', '{PRODUCT_PRICE}', '{PRODUCT_PRICE_DISCOUNT}'), array( (isset($datas['picturesLarge'][0]) ? '' : ''), (isset($datas['picturesMedium'][1]) ? '' : ''), (isset($datas['picturesMedium'][2]) ? '' : ''), (isset($datas['picturesMedium'][3]) ? '' : ''), '', '' ), $datas['description'] ); // Multi Sku case // Check if product exists on eBay $itemID = Db::getInstance()->getValue('SELECT `id_product_ref` FROM `'._DB_PREFIX_.'ebay_product` WHERE `id_product` = '.(int)$product->id); if ($itemID) { // Update $datas['itemID'] = $itemID; if ($ebay->reviseFixedPriceItemMultiSku($datas)) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_product', array('date_upd' => pSQL($date)), 'UPDATE', '`id_product_ref` = '.(int)$itemID); // if product not on eBay we add it if ($ebay->errorCode == 291) { // We delete from DB and Add it on eBay Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'ebay_product` WHERE `id_product_ref` = \''.pSQL($datas['itemID']).'\''); $ebay->addFixedPriceItemMultiSku($datas); if ($ebay->itemID > 0) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_product', array('id_country' => 8, 'id_product' => (int)$product->id, 'id_attribute' => 0, 'id_product_ref' => pSQL($ebay->itemID), 'date_add' => pSQL($date), 'date_upd' => pSQL($date)), 'INSERT'); } } else { // Add $ebay->addFixedPriceItemMultiSku($datas); if ($ebay->itemID > 0) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_product', array('id_country' => 8, 'id_product' => (int)$product->id, 'id_attribute' => 0, 'id_product_ref' => pSQL($ebay->itemID), 'date_add' => pSQL($date), 'date_upd' => pSQL($date)), 'INSERT'); } } else { // No Multi Sku case foreach ($datas['variations'] as $v) { $datasTmp = $datas; if (isset($v['pictures']) && count($v['pictures']) > 0) $datasTmp['pictures'] = $v['pictures']; if (isset($v['picturesMedium']) && count($v['picturesMedium']) > 0) $datasTmp['picturesMedium'] = $v['picturesMedium']; if (isset($v['picturesLarge']) && count($v['picturesLarge']) > 0) $datasTmp['picturesLarge'] = $v['picturesLarge']; foreach ($v['variations'] as $vLabel) { $datasTmp['name'] .= ' '.$vLabel['value']; $datasTmp['attributes'][$vLabel['name']] = $vLabel['value']; } $datasTmp['price'] = $v['price']; if (isset($v['price_original'])) { $datasTmp['price_original'] = $v['price_original']; $datasTmp['price_percent'] = $v['price_percent']; } $datasTmp['quantity'] = $v['quantity']; $datasTmp['id_attribute'] = $v['id_attribute']; unset($datasTmp['variations']); unset($datasTmp['variationsList']); // Load eBay Description $datasTmp['description'] = str_replace( array('{MAIN_IMAGE}', '{MEDIUM_IMAGE_1}', '{MEDIUM_IMAGE_2}', '{MEDIUM_IMAGE_3}', '{PRODUCT_PRICE}', '{PRODUCT_PRICE_DISCOUNT}'), array( (isset($datasTmp['picturesLarge'][0]) ? '' : ''), (isset($datasTmp['picturesMedium'][1]) ? '' : ''), (isset($datasTmp['picturesMedium'][2]) ? '' : ''), (isset($datasTmp['picturesMedium'][3]) ? '' : ''), Tools::displayPrice($datasTmp['price']), (isset($datasTmp['price_original']) ? 'au lieu de '.Tools::displayPrice($datasTmp['price_original']).' (remise de '.round($datasTmp['price_percent']).'%)' : ''), ), $datas['description'] ); $datasTmp['id_product'] = (int)$product->id.'-'.(int)$datasTmp['id_attribute']; // Check if product exists on eBay $itemID = Db::getInstance()->getValue('SELECT `id_product_ref` FROM `'._DB_PREFIX_.'ebay_product` WHERE `id_product` = '.(int)$product->id.' AND `id_attribute` = '.(int)$datasTmp['id_attribute']); if ($itemID) { // Update $datasTmp['itemID'] = $itemID; if ($ebay->reviseFixedPriceItem($datasTmp)) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_product', array('date_upd' => pSQL($date)), 'UPDATE', '`id_product_ref` = '.(int)$itemID); // if product not on eBay we add it if ($ebay->errorCode == 291) { // We delete from DB and Add it on eBay Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'ebay_product` WHERE `id_product_ref` = \''.pSQL($datasTmp['itemID']).'\''); $ebay->addFixedPriceItem($datasTmp); if ($ebay->itemID > 0) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_product', array('id_country' => 8, 'id_product' => (int)$product->id, 'id_attribute' => (int)$datasTmp['id_attribute'], 'id_product_ref' => pSQL($ebay->itemID), 'date_add' => pSQL($date), 'date_upd' => pSQL($date)), 'INSERT'); } } else { // Add $ebay->addFixedPriceItem($datasTmp); if ($ebay->itemID > 0) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_product', array('id_country' => 8, 'id_product' => (int)$product->id, 'id_attribute' => (int)$datasTmp['id_attribute'], 'id_product_ref' => pSQL($ebay->itemID), 'date_add' => pSQL($date), 'date_upd' => pSQL($date)), 'INSERT'); } } } } else { // No variations case // Load eBay Description $datas['description'] = str_replace( array('{MAIN_IMAGE}', '{MEDIUM_IMAGE_1}', '{MEDIUM_IMAGE_2}', '{MEDIUM_IMAGE_3}', '{PRODUCT_PRICE}', '{PRODUCT_PRICE_DISCOUNT}'), array( (isset($datas['picturesLarge'][0]) ? '' : ''), (isset($datas['picturesMedium'][1]) ? '' : ''), (isset($datas['picturesMedium'][2]) ? '' : ''), (isset($datas['picturesMedium'][3]) ? '' : ''), Tools::displayPrice($datas['price']), (isset($datas['price_original']) ? 'au lieu de '.Tools::displayPrice($datas['price_original']).' (remise de '.round($datas['price_percent']).'%)' : ''), ), $datas['description'] ); // Check if product exists on eBay $itemID = Db::getInstance()->getValue('SELECT `id_product_ref` FROM `'._DB_PREFIX_.'ebay_product` WHERE `id_product` = '.(int)$product->id); if ($itemID) { // Update $datas['itemID'] = $itemID; if ($ebay->reviseFixedPriceItem($datas)) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_product', array('date_upd' => pSQL($date)), 'UPDATE', '`id_product_ref` = '.(int)$itemID); // if product not on eBay we add it if ($ebay->errorCode == 291) { // We delete from DB and Add it on eBay Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'ebay_product` WHERE `id_product_ref` = \''.pSQL($datas['itemID']).'\''); $ebay->addFixedPriceItem($datas); if ($ebay->itemID > 0) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_product', array('id_country' => 8, 'id_product' => (int)$product->id, 'id_attribute' => 0, 'id_product_ref' => pSQL($ebay->itemID), 'date_add' => pSQL($date), 'date_upd' => pSQL($date)), 'INSERT'); } } else { // Add $ebay->addFixedPriceItem($datas); if ($ebay->itemID > 0) Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_product', array('id_country' => 8, 'id_product' => (int)$product->id, 'id_attribute' => 0, 'id_product_ref' => pSQL($ebay->itemID), 'date_add' => pSQL($date), 'date_upd' => pSQL($date)), 'INSERT'); } } // Check error if (!empty($ebay->error)) { $tab_error[md5($ebay->error)]['msg'] = $ebay->error; if (!isset($tab_error[md5($ebay->error)]['products'])) $tab_error[md5($ebay->error)]['products'] = array(); if (count($tab_error[md5($ebay->error)]['products']) < 10) $tab_error[md5($ebay->error)]['products'][] = $datas['name']; if (count($tab_error[md5($ebay->error)]['products']) == 10) $tab_error[md5($ebay->error)]['products'][] = '...'; $count_error++; } else $count_success++; $count++; } } if ($count_success > 0) $this->_html .= $this->displayConfirmation($this->l('Settings updated').' ('.$this->l('Option').' '.Configuration::get('EBAY_SYNC_MODE').' : '.$count_success.'/'.$count.' '.$this->l('product(s) sync with eBay').')'); if ($count_error > 0) { foreach ($tab_error as $error) { $productsDetails = '
'.$this->l('Product(s) concerned').' :'; foreach ($error['products'] as $product) $productsDetails .= '
- '.$product; $this->_html .= $this->displayError($error['msg'].'
'.$productsDetails); } } } /******************************************************************/ /** Help Config Methods *******************************************/ /******************************************************************/ private function _displayHelp() { return '

Si vous avez des suggestions sur le module eBay, veuillez les postez sur le Forum http://www.prestashop.com/forums/viewforum/134/ebay/


Sommaire

Comment lancer lancer sur eBay ?

  1. S’inscrire en tant que vendeur professionnel
  2. Vérification du statut de professionnel
  3. Lier son compte PayPal à son compte eBay
  4. Configurer son compte vendeur et sa boutique eBay

Le Module Prestashop, comment ça marche ?

Conseils & Astuces pour bien vendre sur eBay




Comment se lancer sur eBay ?

Plus d’infos et tous les liens sur www.inscriptionpro.com


4 Etapes pour s’inscrire sur eBay

A noter : dès votre inscription en tant que professionnel sur eBay.fr, vous recevrez automatiquement un email (dans les 48h) de notre service dédié à l’intégration afin de vous aider dans cette démarche.
Vous pouvez contacter directement notre service “Inscription Pro” par email : inscriptionpro@ebay.com


1) Inscription en tant que vendeur professionnel

L’inscription se fait directement sur eBay.fr via un formulaire. Choisissez un pseudo, un mot de passe, saisissez vos informations personnelles (adresse, téléphone…) et le tour est joué.


2) Vérification de votre statut professionnel

Envoyez à notre service clients les documents justifiant votre statut professionnel.


3) Liez votre compte PayPal à votre compte eBay

Si vous n’avez pas de compte PayPal Business, il faut d’abord vous en créer un directement sur le site de PayPal : créez votre compte PayPal business
Si vous avez déjà un compte PayPal, liez-le à votre compte eBay pour recevoir les paiements des acheteurs et payer automatiquement les frais eBay.


4) Configurez votre compte vendeur et votre Boutique eBay


Vous n’avez plus qu’à mettre en ligne vos produits avec le module eBay de Prestashop !




Le module eBay de Prestashop : comment ça marche ?

1) Onglet « Paramètres »

Cette section est à configurer lors de la première utilisation du module.
Vous devez définir votre compte PayPal comme moyen de paiement de produits sur eBay en renseignant l’email que vous utilisez pour votre compte PayPal.
Si vous n’en avez pas, vous devez souscrire à un compte PayPal Business.
Vous devez définir le moyen et les frais de livraison qui seront appliqués à vos produits sur eBay.

2) Onglet « Configuration des catégories »

Avant de publier vos produits sur eBay, vous devez associer les catégories de produits de votre boutique Prestashop avec celles d’eBay. Vous pouvez également choisir de vendre les produits de votre boutique Prestashop à un prix différent sur eBay. Cet impact sur le prix est défini en %.

NB : Certaines catégories bénéficient du nouveau format d’annonce multi-versions.


3) Onglet « Template de la fiche produit »

Afin d’optimiser le design de vos fiches produits sur eBay, vous pouvez personnaliser le header et le footer de vos annonces en créant un template qui s’appliquera à l’ensemble de vos produits sur eBay. En designant vos annonces selon votre charte graphique (logo, couleurs…), vous développez votre notoriété et votre visibilité sur eBay. De plus, un template d’annonce bien travaillé et présenté de manière agréable et professionnelle fait souvent la différence auprès des acheteurs.


4) Onglet « Mise en ligne des produits »

Cette section vous permet de mettre effectivement en ligne vos produits sur eBay. Vous avez le choix de placer la totalité des produits de votre boutique Prestashop sur eBay (option recommandée) ou seulement certaines catégories.

Rappel : Si vous avez une Boutique eBay, vous ne paierez aucun frais d’insertion pour mettre vos produits en ligne sur eBay.





Conseils & astuces pour bien vendre sur eBay.fr

Conseil N°1 : Avoir une bonne fiche produit

Sur eBay, comme ailleurs, il faut soigner la présentation de ses produits sous peine de ne pas atteindre le niveau de ventes attendu. Un produit mal photographié et mal décrit ne se vendra pas. Il y a donc certaines normes à respecter avant de mettre en ligne ses produits sur eBay.fr. Cela vous permettra de bénéficier d’un bon référencement de vos produits sur eBay, d’optimiser vos ventes et ainsi de développer d’une visibilité optimale.


Conseil N°2 : Avoir un bon profil vendeur

eBay est la seule place de marché en France à vous donner la propriété du client. Vous êtes donc responsable de la relation client avec vos acheteurs qui vous évaluent en tant que vendeur. Pour avoir donc un bon profil vendeur, de bonnes évaluations et ainsi augmentez la confiance de vos acheteurs, il vous faut évidemment remplir vos obligations de vendeur mais aussi soigner votre relation client.

Vous devez avoir un objectif en taux de satisfaction (évaluations) de votre profil vendeur de minimum 4.8/5.
Cette notation influence beaucoup le référencement de vos annonces dans eBay.
Voici comment les 4 critères sur lesquels vous devez soigner votre niveau de service client pour atteindre cet objectif de 4.8 de taux de satisfaction sur votre profil vendeur :

NB : L’outil « Gestionnaire de Ventes Pro » vous permet d’automatiser un certain nombre de ses tâches de relation client et ainsi de vous faire gagner du temps.
Souscrire au Gestionnaire de ventes Pro

'; } public function displayInfoByCart() { } private function _displayFormProduct() { } private function _displayFormAssociation() { } } ?>