// 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:
+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
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user