// Carrier association + discount association

This commit is contained in:
rMalie
2011-07-22 15:53:07 +00:00
parent 0652f0a5de
commit 0aba3ba000
12 changed files with 93 additions and 75 deletions
+9 -6
View File
@@ -42,12 +42,15 @@ class AdminCarriers extends AdminTab
$this->fieldImageSettings = array('name' => 'logo', 'dir' => 's');
$this->fieldsDisplay = array(
'id_carrier' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Name'), 'width' => 100),
'logo' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 's', 'orderby' => false, 'search' => false),
'delay' => array('title' => $this->l('Delay'), 'width' => 300, 'orderby' => false),
'active' => array('title' => $this->l('Status'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false),
'is_free' => array('title' => $this->l('Is Free'), 'align' => 'center', 'icon' => array(0 => 'disabled.gif', 1 => 'enabled.gif', 'default' => 'disabled.gif'), 'type' => 'bool', 'orderby' => false));
'id_carrier' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Name'), 'width' => 100),
'logo' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 's', 'orderby' => false, 'search' => false),
'delay' => array('title' => $this->l('Delay'), 'width' => 300, 'orderby' => false),
'active' => array('title' => $this->l('Status'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false),
'is_free' => array('title' => $this->l('Is Free'), 'align' => 'center', 'icon' => array(0 => 'disabled.gif', 1 => 'enabled.gif', 'default' => 'disabled.gif'), 'type' => 'bool', 'orderby' => false)
);
$this->_group = 'GROUP BY a.id_carrier';
$this->optionTitle = $this->l('Carrier options');
$this->_fieldsOptions = array(
+22 -15
View File
@@ -36,9 +36,9 @@ class AdminDiscounts extends AdminTab
$this->edit = true;
$this->delete = true;
$this->_select = 'dtl.`name` AS discount_type, s.name shop_name,
IF(a.id_discount_type = 1, CONCAT(a.value, " %"),
IF(a.id_discount_type = 2, CONCAT(a.value, " ", c.sign),
"--")) as strvalue';
IF(a.id_discount_type = 1, CONCAT(a.value, " %"),
IF(a.id_discount_type = 2, CONCAT(a.value, " ", c.sign),
"--")) as strvalue';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'currency` c ON (c.`id_currency` = a.`id_currency`)
LEFT JOIN `'._DB_PREFIX_.'discount_type` dt ON (dt.`id_discount_type` = a.`id_discount_type`)
LEFT JOIN `'._DB_PREFIX_.'shop` s ON (s.`id_shop` = a.`id_shop`)
@@ -50,19 +50,20 @@ class AdminDiscounts extends AdminTab
$typesArray[$type['id_discount_type']] = $type['name'];
$this->fieldsDisplay = array(
'id_discount' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Code'), 'width' => 85, 'prefix' => '<span class="discount_name">', 'suffix' => '</span>', 'filter_key' => 'a!name'),
'shop_name' => array('title' => $this->l('Shop'), 'width' => 85, 'filter_key' => 's!name'),
'description' => array('title' => $this->l('Description'), 'width' => 100, 'filter_key' => 'b!description'),
'discount_type' => array('title' => $this->l('Type'), 'type' => 'select', 'select' => $typesArray, 'filter_key' => 'dt!id_discount_type'),
'strvalue' => array('title' => $this->l('Value'), 'width' => 50, 'align' => 'right', 'filter_key' => 'a!value'),
'quantity' => array('title' => $this->l('Qty'), 'width' => 40, 'align' => 'right'),
'date_to' => array('title' => $this->l('To'), 'width' => 60, 'type' => 'date', 'align' => 'right'),
'active' => array('title' => $this->l('Status'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false));
'id_discount' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Code'), 'width' => 85, 'prefix' => '<span class="discount_name">', 'suffix' => '</span>', 'filter_key' => 'a!name'),
'shop_name' => array('title' => $this->l('Shop'), 'width' => 85, 'filter_key' => 's!name'),
'description' => array('title' => $this->l('Description'), 'width' => 100, 'filter_key' => 'b!description'),
'discount_type' => array('title' => $this->l('Type'), 'type' => 'select', 'select' => $typesArray, 'filter_key' => 'dt!id_discount_type'),
'strvalue' => array('title' => $this->l('Value'), 'width' => 50, 'align' => 'right', 'filter_key' => 'a!value'),
'quantity' => array('title' => $this->l('Qty'), 'width' => 40, 'align' => 'right'),
'date_to' => array('title' => $this->l('To'), 'width' => 60, 'type' => 'date', 'align' => 'right'),
'active' => array('title' => $this->l('Status'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false),
);
$this->optionTitle = $this->l('Discounts options');
$this->_fieldsOptions = array(
'PS_VOUCHERS' => array('title' => $this->l('Enable vouchers:'), 'desc' => $this->l('Allow the use of vouchers in shop'), 'cast' => 'intval', 'type' => 'bool'),
'PS_VOUCHERS' => array('title' => $this->l('Enable vouchers:'), 'desc' => $this->l('Allow the use of vouchers in shop'), 'cast' => 'intval', 'type' => 'bool'),
);
parent::__construct();
}
@@ -445,8 +446,14 @@ class AdminDiscounts extends AdminTab
<input type="radio" name="active" id="active_off" value="0" '.(!$this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
<label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p>'.$this->l('Enable or disable voucher').'</p>
</div>
<div class="margin-form">
</div>';
if (Tools::isMultiShopActivated())
{
echo '<label>'.$this->l('Shop association:').'</label><div class="margin-form">';
$this->displayAssoShop();
echo '</div>';
}
echo ' <div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
+1
View File
@@ -144,6 +144,7 @@ class AdminShop extends AdminTab
'contact' => $this->l('Contact'),
'country' => $this->l('Countries'),
'currency' => $this->l('Currencies'),
'discount' => $this->l('Discounts'),
'image' => $this->l('Images'),
'lang' => $this->l('Langs'),
'manufacturer' => $this->l('Manufacturers'),
+10 -7
View File
@@ -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
View File
@@ -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 :
+4 -4
View File
@@ -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
View File
@@ -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);
+1
View File
@@ -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'),
+7 -4
View File
@@ -541,8 +541,6 @@ CREATE TABLE `PREFIX_delivery` (
CREATE TABLE `PREFIX_discount` (
`id_discount` int(10) unsigned NOT NULL auto_increment,
`id_group_shop` INT(11) UNSIGNED NOT NULL DEFAULT '1',
`id_shop` INT(11) UNSIGNED NOT NULL DEFAULT '1',
`id_discount_type` int(10) unsigned NOT NULL,
`behavior_not_exhausted` TINYINT(3) DEFAULT '1',
`id_customer` int(10) unsigned NOT NULL,
@@ -562,8 +560,6 @@ CREATE TABLE `PREFIX_discount` (
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id_discount`),
KEY `id_group_shop` (`id_group_shop`),
KEY `id_shop` (`id_shop`),
KEY `discount_name` (`name`),
KEY `discount_customer` (`id_customer`),
KEY `id_discount_type` (`id_discount_type`)
@@ -1897,4 +1893,11 @@ CREATE TABLE `PREFIX_scene_shop` (
`id_shop` INT( 11 ) UNSIGNED NOT NULL,
PRIMARY KEY (`id_scene`, `id_shop`),
KEY `id_shop` (`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
CREATE TABLE `PREFIX_discount_shop` (
`id_discount` INT( 11 ) UNSIGNED NOT NULL ,
`id_shop` INT( 11 ) UNSIGNED NOT NULL,
PRIMARY KEY (`id_discount`, `id_shop`),
KEY `id_shop` (`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
+10 -3
View File
@@ -119,9 +119,6 @@ CREATE TABLE `PREFIX_currency_shop` (
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
INSERT INTO `PREFIX_currency_shop` (id_shop, id_currency) (SELECT 1, id_currency FROM PREFIX_currency);
ALTER TABLE `PREFIX_discount` ADD `id_group_shop` INT(11) UNSIGNED NOT NULL DEFAULT '1' AFTER `id_discount`, ADD `id_shop` INT(11) UNSIGNED NOT NULL DEFAULT '1' AFTER `id_group_shop`;
ALTER TABLE `PREFIX_discount` ADD INDEX `id_group_shop` (`id_group_shop`), ADD INDEX `id_shop` (`id_shop`);
ALTER TABLE `PREFIX_cart` ADD `id_group_shop` INT(11) UNSIGNED NOT NULL DEFAULT '1' AFTER `id_cart` , ADD `id_shop` INT(11) UNSIGNED NOT NULL DEFAULT '1' AFTER `id_group_shop`, ADD INDEX `id_group_shop` (`id_group_shop`), ADD INDEX `id_shop` (`id_shop`);
ALTER TABLE `PREFIX_customer` ADD `id_group_shop` INT(11) UNSIGNED NOT NULL DEFAULT '1' AFTER `id_customer` , ADD `id_shop` INT(11) UNSIGNED NOT NULL DEFAULT '1' AFTER `id_group_shop`, ADD INDEX `id_group_shop` (`id_group_shop`), ADD INDEX `id_shop` (`id_shop`);
@@ -312,5 +309,15 @@ CREATE TABLE `PREFIX_scene_shop` (
PRIMARY KEY (`id_scene`, `id_shop`),
KEY `id_shop` (`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
INSERT INTO `PREFIX_scene_shop` (id_shop, id_scene) (SELECT 1, id_scene FROM PREFIX_scene);
CREATE TABLE `PREFIX_discount_shop` (
`id_discount` INT( 11 ) UNSIGNED NOT NULL ,
`id_shop` INT( 11 ) UNSIGNED NOT NULL,
PRIMARY KEY (`id_discount`, `id_shop`),
KEY `id_shop` (`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
INSERT INTO `PREFIX_discount_shop` (id_shop, id_discount) (SELECT 1, id_discount FROM PREFIX_discount);
/* PHP:create_multistore(); */
+1 -1
View File
@@ -60,7 +60,7 @@ class BlockCurrencies extends Module
if (Configuration::get('PS_CATALOG_MODE'))
return ;
$currencies = Currency::getCurrencies(false, 1, $this->context);
$currencies = Currency::getCurrencies();
if (!sizeof($currencies))
return '';
$this->context->smarty->assign('currencies', $currencies);
+3 -3
View File
@@ -399,13 +399,13 @@ class MondialRelay extends Module
SELECT c.*, cl.delay
FROM `'._DB_PREFIX_.'mr_method` m
LEFT JOIN `'._DB_PREFIX_.'carrier` c ON (c.`id_carrier` = m.`id_carrier` and c.`deleted` = 0)
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_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).')' : '').'
($id_zone ? 'LEFT JOIN `'._DB_PREFIX_.'zone` z ON (z.`id_zone` = '.(int)$id_zone.')' : '').'
WHERE 1 '.
($id_iso_code ? ' AND m.`mr_Pays_list` LIKE \'%'.pSQL($id_iso_code).'%\'' : '').
($active ? ' AND c.`active` = 1' : '').
($id_zone ? ' AND cz.`id_zone` = '.(int)($id_zone).'
($id_zone ? ' AND cz.`id_zone` = '.(int)$id_zone.'
AND z.`active` = 1' : '').'
GROUP BY c.`id_carrier`');