// Carrier association + discount association
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7696 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+10
-7
@@ -98,6 +98,8 @@ abstract class AdminTabCore
|
||||
|
||||
/** @var bool */
|
||||
public $shopShareDatas = false;
|
||||
|
||||
public $shopAssoName = 'name';
|
||||
|
||||
/** @var array Cache for query results */
|
||||
protected $_list = array();
|
||||
@@ -275,9 +277,9 @@ abstract class AdminTabCore
|
||||
$this->includeSubTab('display');
|
||||
$assos_shop = Shop::getAssoTables();
|
||||
if (isset($assos_shop[$this->table]) AND $assos_shop[$this->table]['type'] == 'shop')
|
||||
$this->displayAssoShop();
|
||||
$this->displayAssoShop($this->shopAssoName);
|
||||
elseif (isset($assos_shop[$this->table]) AND $assos_shop[$this->table]['type'] == 'group_shop')
|
||||
$this->displayAssoGroupShop();
|
||||
$this->displayAssoGroupShop($this->shopAssoName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1971,17 +1973,18 @@ abstract class AdminTabCore
|
||||
$this->l('Click here if you want to modify the main shop domain name').'</a>');
|
||||
}
|
||||
|
||||
protected function displayAssoShop($field_name = 'name')
|
||||
protected function displayAssoShop($field_name = 'name', $selectName = null)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
if (!Tools::isMultiShopActivated() || (!$this->_object && $context->shop->getContextType() != Shop::CONTEXT_ALL))
|
||||
return;
|
||||
|
||||
$shops = Shop::getShops();
|
||||
$objects = Db::getInstance()->ExecuteS('SELECT DISTINCT a.`'.pSQL($this->identifier).'`, '.(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? 'b' : 'a').'.`'.pSQL($field_name).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'`a '.
|
||||
(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? ' LEFT JOIN `'._DB_PREFIX_.pSQL($this->table).'_lang` b ON (a.`'.pSQL($this->identifier).'`=b.`'.pSQL($this->identifier).'`)' : '').
|
||||
' WHERE 1'.(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? ' AND b.id_lang='.(int)$context->language->id : '').($this->_object ? ' AND a.`'.pSQL($this->identifier).'`='.(int)$this->_object->id : ''));
|
||||
$sql = 'SELECT DISTINCT a.`'.pSQL($this->identifier).'`, '.(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? 'b' : 'a').'.`'.pSQL($field_name).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'`a '.
|
||||
(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? ' LEFT JOIN `'._DB_PREFIX_.pSQL($this->table).'_lang` b ON (a.`'.pSQL($this->identifier).'`=b.`'.pSQL($this->identifier).'`)' : '').
|
||||
' WHERE 1'.(($this->lang AND isset($this->fieldsDisplay[$field_name]['filter_key']) AND $this->fieldsDisplay[$field_name]['filter_key'] == 'b!'.$field_name) ? ' AND b.id_lang='.(int)$context->language->id : '').($this->_object ? ' AND a.`'.pSQL($this->identifier).'`='.(int)$this->_object->id : '');
|
||||
$objects = Db::getInstance()->ExecuteS($sql);
|
||||
$assos = array();
|
||||
$res = Db::getInstance()->ExecuteS('SELECT id_shop, `'.pSQL($this->identifier).'`
|
||||
FROM `'._DB_PREFIX_.pSQL($this->table).'_shop`');
|
||||
|
||||
+12
-10
@@ -73,6 +73,8 @@ class CarrierCore extends ObjectModel
|
||||
|
||||
/** @var boolean Need Range */
|
||||
public $need_range = 0;
|
||||
|
||||
protected $langMultiShop = true;
|
||||
|
||||
protected $fieldsRequired = array('name', 'active');
|
||||
protected $fieldsSize = array('name' => 64);
|
||||
@@ -342,16 +344,16 @@ class CarrierCore extends ObjectModel
|
||||
if ($ids == '')
|
||||
return (array());
|
||||
}
|
||||
$sql = '
|
||||
SELECT c.*, cl.delay
|
||||
FROM `'._DB_PREFIX_.'carrier` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'carrier_lang` cl ON (c.`id_carrier` = cl.`id_carrier` AND cl.`id_lang` = '.(int)($id_lang).')
|
||||
LEFT JOIN `'._DB_PREFIX_.'carrier_zone` cz ON (cz.`id_carrier` = c.`id_carrier`)'.
|
||||
($id_zone ? 'LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = '.(int)($id_zone).')' : '').'
|
||||
WHERE c.`deleted` '.($delete ? '= 1' : ' = 0').
|
||||
($active ? ' AND c.`active` = 1' : '').
|
||||
($id_zone ? ' AND cz.`id_zone` = '.(int)($id_zone).'
|
||||
AND z.`active` = 1 ' : ' ');
|
||||
|
||||
$sql = 'SELECT c.*, cl.delay
|
||||
FROM `'._DB_PREFIX_.'carrier` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'carrier_lang` cl ON (c.`id_carrier` = cl.`id_carrier` AND cl.`id_lang` = '.(int)$id_lang.Context::getContext()->shop->sqlLang('cl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'carrier_zone` cz ON (cz.`id_carrier` = c.`id_carrier`)'.
|
||||
($id_zone ? 'LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = '.(int)$id_zone.')' : '').'
|
||||
WHERE c.`deleted` = '.($delete ? '1' : '0').
|
||||
($active ? ' AND c.`active` = 1' : '').
|
||||
($id_zone ? ' AND cz.`id_zone` = '.(int)$id_zone.'
|
||||
AND z.`active` = 1 ' : ' ');
|
||||
switch ($modules_filters)
|
||||
{
|
||||
case 1 :
|
||||
|
||||
@@ -180,14 +180,14 @@ class CurrencyCore extends ObjectModel
|
||||
*
|
||||
* @return array Currencies
|
||||
*/
|
||||
static public function getCurrencies($object = false, $active = 1, Context $context = null)
|
||||
static public function getCurrencies($object = false, $active = 1, Shop $shop = null)
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
if (!$shop)
|
||||
$shop = new Shop(Context::getContext()->shop->getID(true));
|
||||
|
||||
$sql = 'SELECT *
|
||||
FROM `'._DB_PREFIX_.'currency` c
|
||||
'.$context->shop->sqlAsso('currency', 'c', false).'
|
||||
'.$shop->sqlAsso('currency', 'c', false).'
|
||||
WHERE `deleted` = 0'
|
||||
.($active == 1 ? ' AND c.`active` = 1' : '').'
|
||||
ORDER BY `name` ASC';
|
||||
|
||||
+13
-22
@@ -28,10 +28,6 @@
|
||||
class DiscountCore extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
|
||||
public $id_group_shop;
|
||||
|
||||
public $id_shop;
|
||||
|
||||
/** @var integer Customer id only if discount is reserved */
|
||||
public $id_customer;
|
||||
@@ -132,8 +128,6 @@ class DiscountCore extends ObjectModel
|
||||
{
|
||||
parent::validateFields();
|
||||
|
||||
$fields['id_group_shop'] = (int)$this->id_group_shop;
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
$fields['id_customer'] = (int)($this->id_customer);
|
||||
$fields['id_group'] = (int)($this->id_group);
|
||||
$fields['id_currency'] = (int)($this->id_currency);
|
||||
@@ -260,13 +254,12 @@ class DiscountCore extends ObjectModel
|
||||
|
||||
public function usedByCustomer($id_customer)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'order_discount` od
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`)
|
||||
WHERE od.`id_discount` = '.(int)($this->id).'
|
||||
AND o.`id_customer` = '.(int)($id_customer)
|
||||
);
|
||||
$sql = 'SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'order_discount` od
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (od.`id_order` = o.`id_order`)
|
||||
WHERE od.`id_discount` = '.(int)$this->id.'
|
||||
AND o.`id_customer` = '.(int)$id_customer;
|
||||
return Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,23 +271,25 @@ class DiscountCore extends ObjectModel
|
||||
*/
|
||||
public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true, Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$totalAmount = 0;
|
||||
|
||||
$cart = new Cart((int)($idCart));
|
||||
$cart = new Cart($idCart);
|
||||
if (!Validate::isLoadedObject($cart))
|
||||
return 0;
|
||||
|
||||
if ((!$this->cumulable AND (int)($nb_discounts) > 1) OR !$this->active OR (!$this->quantity AND !$cart->OrderExists()))
|
||||
if ((!$this->cumulable AND (int)$nb_discounts > 1) OR !$this->active OR (!$this->quantity AND !$cart->OrderExists()))
|
||||
return 0;
|
||||
|
||||
if ($this->usedByCustomer((int)($cart->id_customer)) >= $this->quantity_per_user AND !$cart->OrderExists())
|
||||
if ($this->usedByCustomer((int)$cart->id_customer) >= $this->quantity_per_user AND !$cart->OrderExists())
|
||||
return 0;
|
||||
|
||||
$date_start = strtotime($this->date_from);
|
||||
$date_end = strtotime($this->date_to);
|
||||
if ((time() < $date_start OR time() > $date_end) AND !$cart->OrderExists()) return 0;
|
||||
|
||||
if (!$this->availableWithShop(Context::getContext()->shop))
|
||||
if (!$this->isAssociatedToShop($context->shop->shopID()))
|
||||
return 0;
|
||||
$products = $cart->getProducts();
|
||||
$categories = Discount::getCategories((int)$this->id);
|
||||
@@ -322,8 +317,6 @@ class DiscountCore extends ObjectModel
|
||||
/* Absolute value */
|
||||
case 2:
|
||||
// An "absolute" voucher is available in one currency only
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
$currency = ((int)$cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : $context->currency);
|
||||
if ($this->id_currency != $currency->id)
|
||||
return 0;
|
||||
@@ -439,8 +432,6 @@ class DiscountCore extends ObjectModel
|
||||
$voucher->minimal = (float)($voucher->value);
|
||||
$voucher->active = 1;
|
||||
$voucher->cart_display = 1;
|
||||
$voucher->id_group_shop = (int)$order->id_group_shop;
|
||||
$voucher->id_shop = (int)$order->id_shop;
|
||||
|
||||
$now = time();
|
||||
$voucher->date_from = date('Y-m-d H:i:s', $now);
|
||||
|
||||
@@ -63,6 +63,7 @@ class ShopCore extends ObjectModel
|
||||
'contact' => array('type' => 'shop'),
|
||||
'country' => array('type' => 'shop'),
|
||||
'currency' => array('type' => 'shop'),
|
||||
'discount' => array('type' => 'shop'),
|
||||
'hook_module' => array('type' => 'fk_shop'),
|
||||
'hook_module_exceptions' => array('type' => 'fk_shop', 'primary' => 'id_hook_module_exceptions'),
|
||||
'image' => array('type' => 'shop'),
|
||||
|
||||
Reference in New Issue
Block a user