// Merge -> revision 7875
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7877 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -12,7 +12,8 @@ if (file_exists($configPath))
|
||||
$nbProducts = 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)');
|
||||
WHERE `quantity` > 0 AND `active` = 1
|
||||
AND `id_category_default` IN (SELECT `id_category` FROM `'._DB_PREFIX_.'ebay_category_configuration` WHERE `id_ebay_category` > 0 AND `sync` = 1)');
|
||||
|
||||
echo $nbProducts;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<module>
|
||||
<name>ebay</name>
|
||||
<displayName><![CDATA[eBay]]></displayName>
|
||||
<version><![CDATA[1.1]]></version>
|
||||
<version><![CDATA[1.2]]></version>
|
||||
<description><![CDATA[Open your shop on the eBay market place !]]></description>
|
||||
<author><![CDATA[]]></author>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[market_place]]></tab>
|
||||
<is_configurable>1</is_configurable>
|
||||
<need_instance>1</need_instance>
|
||||
|
||||
@@ -374,7 +374,7 @@ class eBayRequest
|
||||
$requestXml .= ' <ErrorLanguage>fr_FR</ErrorLanguage>'."\n";
|
||||
$requestXml .= ' <WarningLevel>High</WarningLevel>'."\n";
|
||||
$requestXml .= ' <Item>'."\n";
|
||||
$requestXml .= ' <SKU>prestashop-'.$datas['id_product'].'</SKU>';
|
||||
$requestXml .= ' <SKU>prestashop-'.$datas['id_product'].(isset($datas['reference']) ? '-'.$datas['reference'] : '').'</SKU>';
|
||||
$requestXml .= ' <Title>'.substr($datas['name'], 0, 55).'</Title>'."\n";
|
||||
if (isset($datas['pictures']))
|
||||
{
|
||||
@@ -503,7 +503,7 @@ class eBayRequest
|
||||
$requestXml .= ' <WarningLevel>High</WarningLevel>'."\n";
|
||||
$requestXml .= ' <Item>'."\n";
|
||||
$requestXml .= ' <ItemID>'.$datas['itemID'].'</ItemID>'."\n";
|
||||
$requestXml .= ' <SKU>prestashop-'.$datas['id_product'].'</SKU>';
|
||||
$requestXml .= ' <SKU>prestashop-'.$datas['id_product'].(isset($datas['reference']) ? '-'.$datas['reference'] : '').'</SKU>';
|
||||
$requestXml .= ' <Quantity>'.$datas['quantity'].'</Quantity>'."\n";
|
||||
$requestXml .= ' <StartPrice>'.$datas['price'].'</StartPrice>'."\n";
|
||||
if (Configuration::get('EBAY_SYNC_OPTION_RESYNC') != 1)
|
||||
@@ -653,7 +653,7 @@ class eBayRequest
|
||||
foreach ($datas['variations'] as $key => $variation)
|
||||
{
|
||||
$requestXml .= ' <Variation>'."\n";
|
||||
$requestXml .= ' <SKU>prestashop-'.$key.'</SKU>'."\n";
|
||||
$requestXml .= ' <SKU>prestashop-'.$key.(isset($variation['reference']) ? '-'.$variation['reference'] : '').'</SKU>'."\n";
|
||||
$requestXml .= ' <StartPrice>'.$variation['price'].'</StartPrice>'."\n";
|
||||
$requestXml .= ' <Quantity>'.$variation['quantity'].'</Quantity>'."\n";
|
||||
$requestXml .= ' <VariationSpecifics>'."\n";
|
||||
@@ -1005,6 +1005,24 @@ class eBayRequest
|
||||
}
|
||||
if ($id_product > 0)
|
||||
$itemList[] = array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $quantity, 'price' => (string)$transaction->TransactionPrice);
|
||||
else
|
||||
{
|
||||
$id_product = Db::getInstance()->getValue('
|
||||
SELECT `id_product` FROM `'._DB_PREFIX_.'product`
|
||||
WHERE `reference` = \''.pSQL((string)$transaction->item->SKU).'\' OR `reference` = \''.pSQL((string)$transaction->item->CustomLabel).'\'
|
||||
OR `reference` = \''.pSQL((string)$transaction->Variation->SKU).'\' OR `reference` = \''.pSQL((string)$transaction->Variation->CustomLabel).'\'');
|
||||
if ((int)$id_product > 0)
|
||||
$itemList[] = array('id_product' => $id_product, 'quantity' => $quantity, 'price' => (string)$transaction->TransactionPrice);
|
||||
else
|
||||
{
|
||||
$row = Db::getInstance()->getValue('
|
||||
SELECT `id_product`, `id_product_attribute` FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `reference` = \''.pSQL((string)$transaction->item->SKU).'\' OR `reference` = \''.pSQL((string)$transaction->item->CustomLabel).'\'
|
||||
OR `reference` = \''.pSQL((string)$transaction->Variation->SKU).'\' OR `reference` = \''.pSQL((string)$transaction->Variation->CustomLabel).'\'');
|
||||
if ((int)$row['id_product'] > 0)
|
||||
$itemList[] = array('id_product' => $row['id_product'], 'id_product_attribute' => $row['id_product_attribute'], 'quantity' => $quantity, 'price' => (string)$transaction->TransactionPrice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$orderList[] = array(
|
||||
@@ -1014,7 +1032,7 @@ class eBayRequest
|
||||
'date' => substr((string)$order->CreatedTime, 0, 10).' '.substr((string)$order->CreatedTime, 11, 8),
|
||||
'name' => (string)$order->ShippingAddress->Name,
|
||||
'firstname' => $name[0],
|
||||
'familyname' => $name[1],
|
||||
'familyname' => (isset($name[1]) ? $name[1] : $name[0]),
|
||||
'address1' => (string)$order->ShippingAddress->Street1,
|
||||
'address2' => (string)$order->ShippingAddress->Street2,
|
||||
'city' => (string)$order->ShippingAddress->CityName,
|
||||
|
||||
+50
-9
@@ -56,7 +56,8 @@ class Ebay extends Module
|
||||
{
|
||||
$this->name = 'ebay';
|
||||
$this->tab = 'market_place';
|
||||
$this->version = '1.1';
|
||||
$this->version = '1.2';
|
||||
$this->author = 'PrestaShop';
|
||||
parent::__construct ();
|
||||
$this->displayName = $this->l('eBay');
|
||||
$this->description = $this->l('Open your shop on the eBay market place !');
|
||||
@@ -92,6 +93,10 @@ class Ebay extends Module
|
||||
// Check if installed
|
||||
if (self::isInstalled($this->name))
|
||||
{
|
||||
// Upgrade eBay module
|
||||
if (Configuration::get('EBAY_VERSION') != $this->version)
|
||||
$this->upgrade();
|
||||
|
||||
// Generate warnings
|
||||
if (!Configuration::get('EBAY_API_TOKEN'))
|
||||
$this->warning = $this->l('You must register your module on eBay.');
|
||||
@@ -225,6 +230,20 @@ class Ebay extends Module
|
||||
return true;
|
||||
}
|
||||
|
||||
public function upgrade()
|
||||
{
|
||||
$version = Configuration::get('EBAY_VERSION');
|
||||
if ($version == '1.1' || empty($version))
|
||||
{
|
||||
// Upgrade SQL
|
||||
include(dirname(__FILE__).'/sql-upgrade-1-2.php');
|
||||
foreach ($sql as $s)
|
||||
if (!Db::getInstance()->Execute($s))
|
||||
return false;
|
||||
Configuration::updateValue('EBAY_VERSION', $this->version);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
/** Hook Methods **************************************************/
|
||||
@@ -292,15 +311,28 @@ class Ebay extends Module
|
||||
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);
|
||||
$orderList = $ebay->getOrders(date('Y-m-d', strtotime('-90 days')).'T'.date('H:i:s', strtotime('-45 minutes')).'.000Z', $dateNew);
|
||||
|
||||
if ($orderList)
|
||||
foreach ($orderList as $order)
|
||||
if ($order['status'] == 'Complete'&&
|
||||
isset($order['product_list']) && count($order['product_list']))
|
||||
if ($order['status'] == 'Complete' && $order['amount'] > 0.1 && isset($order['product_list']) && count($order['product_list']))
|
||||
{
|
||||
if (!Db::getInstance()->getValue('SELECT `id_ebay_order` FROM `'._DB_PREFIX_.'ebay_order` WHERE `id_order_ref` = \''.pSQL($order['id_order_ref']).'\''))
|
||||
{
|
||||
$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);
|
||||
|
||||
// Check for empty name
|
||||
$order['firstname'] = str_replace('_', '', trim($order['firstname']));
|
||||
$order['familyname'] = str_replace('_', '', trim($order['familyname']));
|
||||
if (empty($order['familyname']))
|
||||
$order['familyname'] = $order['firstname'];
|
||||
if (empty($order['firstname']))
|
||||
$order['firstname'] = $order['familyname'];
|
||||
|
||||
if (Validate::isEmail($order['email']) && !empty($order['firstname']) && !empty($order['familyname']))
|
||||
{
|
||||
|
||||
// Add customer if he doesn't exist
|
||||
if ($id_customer < 1)
|
||||
{
|
||||
@@ -382,6 +414,11 @@ class Ebay extends Module
|
||||
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']);
|
||||
|
||||
// Register the ebay order ref
|
||||
Db::getInstance()->autoExecute(_DB_PREFIX_.'ebay_order', array('id_order_ref' => pSQL($order['id_order_ref']), 'id_order' => (int)$id_order), 'INSERT');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1075,11 +1112,13 @@ class Ebay extends Module
|
||||
$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)');
|
||||
WHERE `quantity` > 0 AND `active` = 1
|
||||
AND `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)');
|
||||
WHERE `quantity` > 0 AND `active` = 1
|
||||
AND `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')
|
||||
@@ -1213,7 +1252,7 @@ class Ebay extends Module
|
||||
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)');
|
||||
$productsList = Db::getInstance()->ExecuteS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `quantity` > 0 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)');
|
||||
|
||||
// Send each product on eBay
|
||||
$this->_syncProducts($productsList);
|
||||
@@ -1227,7 +1266,7 @@ class Ebay extends Module
|
||||
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)');
|
||||
$productsList = Db::getInstance()->ExecuteS('SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `quantity` > 0 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)');
|
||||
|
||||
// Send each product on eBay
|
||||
$this->_syncProducts($productsList);
|
||||
@@ -1282,6 +1321,7 @@ class Ebay extends Module
|
||||
{
|
||||
$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']]['reference'] = $c['reference'];
|
||||
$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']);
|
||||
@@ -1322,6 +1362,7 @@ class Ebay extends Module
|
||||
// Generate array and try insert in database
|
||||
$datas = array(
|
||||
'id_product' => $product->id,
|
||||
'reference' => $product->reference,
|
||||
'name' => str_replace('&', '&', $product->name),
|
||||
'brand' => $product->manufacturer_name,
|
||||
'description' => $product->description,
|
||||
@@ -1688,4 +1729,4 @@ class Ebay extends Module
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -48,5 +48,32 @@
|
||||
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';
|
||||
|
||||
|
||||
// Create Order Table in Database
|
||||
$sql[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ebay_order` (
|
||||
`id_ebay_order` int(16) NOT NULL AUTO_INCREMENT,
|
||||
`id_order_ref` varchar(128) NOT NULL,
|
||||
`id_order` int(16) NOT NULL,
|
||||
UNIQUE(`id_order_ref`),
|
||||
PRIMARY KEY (`id_ebay_order`)
|
||||
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';
|
||||
|
||||
|
||||
// Create Sync History Table in Database
|
||||
$sql[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ebay_sync_history` (
|
||||
`id_ebay_sync_history` int(16) NOT NULL AUTO_INCREMENT,
|
||||
`is_manual` tinyint(1) NOT NULL,
|
||||
`datetime` datetime NOT NULL,
|
||||
PRIMARY KEY (`id_ebay_sync_history`)
|
||||
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';
|
||||
|
||||
|
||||
// Create Sync History Product Table in Database
|
||||
$sql[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ebay_sync_history_product` (
|
||||
`id_ebay_sync_history_product` int(16) NOT NULL AUTO_INCREMENT,
|
||||
`id_ebay_sync_history` int(16),
|
||||
`id_product` int(16),
|
||||
KEY (`id_ebay_sync_history`),
|
||||
PRIMARY KEY (`id_ebay_sync_history_product`)
|
||||
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -5,5 +5,8 @@
|
||||
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'ebay_category`;';
|
||||
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'ebay_category_configuration`;';
|
||||
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'ebay_product`;';
|
||||
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'ebay_order`;';
|
||||
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'ebay_sync_history`;';
|
||||
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'ebay_sync_history_product`;';
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
// Init
|
||||
$sql = array();
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
// Init
|
||||
$sql = array();
|
||||
|
||||
// Create Order Table in Database
|
||||
$sql[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ebay_order` (
|
||||
`id_ebay_order` int(16) NOT NULL AUTO_INCREMENT,
|
||||
`id_order_ref` varchar(128) NOT NULL,
|
||||
`id_order` int(16) NOT NULL,
|
||||
UNIQUE(`id_order_ref`),
|
||||
PRIMARY KEY (`id_ebay_order`)
|
||||
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';
|
||||
|
||||
// Create Sync History Table in Database
|
||||
$sql[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ebay_sync_history` (
|
||||
`id_ebay_sync_history` int(16) NOT NULL AUTO_INCREMENT,
|
||||
`is_manual` tinyint(1) NOT NULL,
|
||||
`datetime` datetime NOT NULL,
|
||||
PRIMARY KEY (`id_ebay_sync_history`)
|
||||
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';
|
||||
|
||||
|
||||
// Create Sync History Product Table in Database
|
||||
$sql[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ebay_sync_history_product` (
|
||||
`id_ebay_sync_history_product` int(16) NOT NULL AUTO_INCREMENT,
|
||||
`id_ebay_sync_history` int(16),
|
||||
`id_product` int(16),
|
||||
KEY (`id_ebay_sync_history`),
|
||||
PRIMARY KEY (`id_ebay_sync_history_product`)
|
||||
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';
|
||||
|
||||
Reference in New Issue
Block a user