// Improve StockAvailable requests + code refactoring
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10855 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -85,20 +85,26 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (($result = Db::getInstance()->executeS('
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT `id_product_attribute`
|
||||
FROM `'._DB_PREFIX_.'product_attribute_combination`
|
||||
WHERE `'.$this->identifier.'` = '.(int)$this->id)) === false)
|
||||
WHERE `'.$this->identifier.'` = '.(int)$this->id
|
||||
);
|
||||
|
||||
if ($result === false)
|
||||
return false;
|
||||
|
||||
$combination_ids = array();
|
||||
if (Db::getInstance()->numRows())
|
||||
{
|
||||
foreach ($result as $row)
|
||||
$combination_ids[] = (int)$row['id_product_attribute'];
|
||||
|
||||
if (Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute_combination`
|
||||
WHERE `'.$this->identifier.'` = '.(int)$this->id) === false)
|
||||
return false;
|
||||
|
||||
if (Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product_attribute` IN ('.implode(', ', $combination_ids).')') === false)
|
||||
@@ -111,14 +117,17 @@ class AttributeCore extends ObjectModel
|
||||
$return = parent::delete();
|
||||
if ($return)
|
||||
Hook::exec('afterDeleteAttribute', array('id_attribute' => $this->id));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function update($null_values = false)
|
||||
{
|
||||
$return = parent::update($null_values);
|
||||
|
||||
if ($return)
|
||||
Hook::exec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -128,8 +137,10 @@ class AttributeCore extends ObjectModel
|
||||
$this->position = Attribute::getHigherPosition($this->id_attribute_group) + 1;
|
||||
|
||||
$return = parent::add($autodate, $null_values);
|
||||
|
||||
if ($return)
|
||||
Hook::exec('afterSaveAttribute', array('id_attribute' => $this->id));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -144,6 +155,7 @@ class AttributeCore extends ObjectModel
|
||||
{
|
||||
if (!Combination::isFeatureActive())
|
||||
return array();
|
||||
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT ag.*, agl.*, a.`id_attribute`, al.`name`, agl.`name` AS `attribute_group`
|
||||
FROM `'._DB_PREFIX_.'attribute_group` ag
|
||||
@@ -173,12 +185,6 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
$result = StockAvailable::getQuantityAvailableByProduct(null, (int)$id_product_attribute, $shop->getID());
|
||||
|
||||
/*$sql = 'SELECT quantity
|
||||
FROM '._DB_PREFIX_.'stock_available
|
||||
WHERE id_product_attribute = '.(int)$id_product_attribute
|
||||
.$shop->addSqlRestriction();
|
||||
$result = (int)Db::getInstance()->getValue($sql);*/
|
||||
|
||||
return ($result && $qty <= $result);
|
||||
}
|
||||
|
||||
@@ -194,18 +200,6 @@ class AttributeCore extends ObjectModel
|
||||
Tools::displayAsDeprecated();
|
||||
|
||||
return StockAvailable::getQuantityAvailableByProduct($id_product);
|
||||
|
||||
/*
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT SUM(quantity) as quantity
|
||||
FROM `'._DB_PREFIX_.'product_attribute`
|
||||
WHERE `id_product` = '.(int)$id_product
|
||||
);
|
||||
|
||||
if ($row['quantity'] !== null)
|
||||
return (int)$row['quantity'];
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,6 +221,7 @@ class AttributeCore extends ObjectModel
|
||||
$arr['quantity'] = (int)$qty;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -247,6 +242,7 @@ class AttributeCore extends ObjectModel
|
||||
WHERE `id_attribute` = '.(int)$this->id.')
|
||||
AND group_type = \'color\''))
|
||||
return false;
|
||||
|
||||
return Db::getInstance()->numRows();
|
||||
}
|
||||
|
||||
@@ -267,6 +263,7 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
if ($minimal_quantity > 1)
|
||||
return (int)$minimal_quantity;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -292,29 +289,28 @@ class AttributeCore extends ObjectModel
|
||||
|
||||
if (!isset($moved_attribute) || !isset($position))
|
||||
return false;
|
||||
p('
|
||||
UPDATE `'._DB_PREFIX_.'attribute`
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way
|
||||
? '> '.(int)$moved_attribute['position'].' AND `position` <= '.(int)$position
|
||||
: '< '.(int)$moved_attribute['position'].' AND `position` >= '.(int)$position).'
|
||||
AND `id_attribute_group`='.(int)$moved_attribute['id_attribute_group']);
|
||||
|
||||
// < and > statements rather than BETWEEN operator
|
||||
// since BETWEEN is treated differently according to databases
|
||||
return (Db::getInstance()->execute('
|
||||
|
||||
$res1 = Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'attribute`
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way
|
||||
? '> '.(int)$moved_attribute['position'].' AND `position` <= '.(int)$position
|
||||
: '< '.(int)$moved_attribute['position'].' AND `position` >= '.(int)$position).'
|
||||
AND `id_attribute_group`='.(int)$moved_attribute['id_attribute_group'])
|
||||
&& Db::getInstance()->execute('
|
||||
AND `id_attribute_group`='.(int)$moved_attribute['id_attribute_group']
|
||||
);
|
||||
|
||||
$res2 = Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'attribute`
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_attribute` = '.(int)$moved_attribute['id_attribute'].'
|
||||
AND `id_attribute_group`='.(int)$moved_attribute['id_attribute_group']));
|
||||
AND `id_attribute_group`='.(int)$moved_attribute['id_attribute_group']
|
||||
);
|
||||
|
||||
return ($res1 && $res2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,24 +326,27 @@ p('
|
||||
$return = true;
|
||||
|
||||
$sql = '
|
||||
SELECT `id_attribute`
|
||||
FROM `'._DB_PREFIX_.'attribute`
|
||||
WHERE `id_attribute_group` = '.(int)$id_attribute_group;
|
||||
SELECT `id_attribute`
|
||||
FROM `'._DB_PREFIX_.'attribute`
|
||||
WHERE `id_attribute_group` = '.(int)$id_attribute_group;
|
||||
|
||||
// when delete, you must use $use_last_attribute
|
||||
if ($use_last_attribute)
|
||||
$sql .= '
|
||||
AND `id_attribute` != '.(int)$this->id;
|
||||
$sql .= '
|
||||
ORDER BY `position`';
|
||||
$sql .= 'AND `id_attribute` != '.(int)$this->id;
|
||||
|
||||
$sql .= 'ORDER BY `position`';
|
||||
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
|
||||
$i = 0;
|
||||
foreach ($result as $value)
|
||||
$return = Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'attribute`
|
||||
SET `position` = '.(int)$i++.'
|
||||
WHERE `id_attribute_group` = '.(int)$id_attribute_group.'
|
||||
AND `id_attribute` = '.(int)$value['id_attribute']);
|
||||
UPDATE `'._DB_PREFIX_.'attribute`
|
||||
SET `position` = '.(int)$i++.'
|
||||
WHERE `id_attribute_group` = '.(int)$id_attribute_group.'
|
||||
AND `id_attribute` = '.(int)$value['id_attribute']
|
||||
);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -364,8 +363,9 @@ p('
|
||||
$sql = 'SELECT MAX(`position`)
|
||||
FROM `'._DB_PREFIX_.'attribute`
|
||||
WHERE id_attribute_group = '.(int)$id_attribute_group;
|
||||
|
||||
$position = DB::getInstance()->getValue($sql);
|
||||
|
||||
return (is_numeric($position)) ? $position : -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1135
classes/Cart.php
1135
classes/Cart.php
File diff suppressed because it is too large
Load Diff
@@ -29,8 +29,8 @@ class ManufacturerCore extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
|
||||
/** @var integer manufacturer ID */
|
||||
public $id_manufacturer;//FIXME is it really usefull...?
|
||||
/** @var integer manufacturer ID //FIXME is it really usefull...? */
|
||||
public $id_manufacturer;
|
||||
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
@@ -68,8 +68,12 @@ class ManufacturerCore extends ObjectModel
|
||||
protected $fieldsRequired = array('name');
|
||||
protected $fieldsSize = array('name' => 64);
|
||||
protected $fieldsValidate = array('name' => 'isCatalogName');
|
||||
|
||||
protected $fieldsSizeLang = array('short_description' => 254, 'meta_title' => 128, 'meta_description' => 255, 'meta_description' => 255);
|
||||
protected $fieldsSizeLang = array(
|
||||
'short_description' => 254,
|
||||
'meta_title' => 128,
|
||||
'meta_description' => 255,
|
||||
'meta_description' => 255
|
||||
);
|
||||
protected $fieldsValidateLang = array(
|
||||
'description' => 'isString',
|
||||
'short_description' => 'isString',
|
||||
@@ -77,10 +81,8 @@ class ManufacturerCore extends ObjectModel
|
||||
'meta_description' => 'isGenericName',
|
||||
'meta_keywords' => 'isGenericName'
|
||||
);
|
||||
|
||||
protected $table = 'manufacturer';
|
||||
protected $identifier = 'id_manufacturer';
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'fields' => array(
|
||||
'active' => array(),
|
||||
@@ -106,18 +108,22 @@ class ManufacturerCore extends ObjectModel
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
|
||||
if (isset($this->id))
|
||||
$fields['id_manufacturer'] = (int)$this->id;
|
||||
|
||||
$fields['name'] = pSQL($this->name);
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
$fields['date_upd'] = pSQL($this->date_upd);
|
||||
$fields['active'] = (int)$this->active;
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getTranslationsFieldsChild()
|
||||
{
|
||||
$this->validateFieldsLang();
|
||||
|
||||
return $this->getTranslationsFields(array(
|
||||
'meta_description',
|
||||
'meta_keywords',
|
||||
@@ -130,8 +136,10 @@ class ManufacturerCore extends ObjectModel
|
||||
public function delete()
|
||||
{
|
||||
$address = new Address($this->id_address);
|
||||
|
||||
if (!$address->delete())
|
||||
return false;
|
||||
|
||||
if (parent::delete())
|
||||
return $this->deleteImage();
|
||||
}
|
||||
@@ -145,6 +153,7 @@ class ManufacturerCore extends ObjectModel
|
||||
{
|
||||
if (!is_array($selection) || !Validate::isTableOrIdentifier($this->identifier) || !Validate::isTableOrIdentifier($this->table))
|
||||
die(Tools::displayError());
|
||||
|
||||
$result = true;
|
||||
foreach ($selection as $id)
|
||||
{
|
||||
@@ -152,6 +161,7 @@ class ManufacturerCore extends ObjectModel
|
||||
$this->id_address = self::getManufacturerAddress();
|
||||
$result = $result && $this->delete();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -159,13 +169,16 @@ class ManufacturerCore extends ObjectModel
|
||||
{
|
||||
if (!(int)$this->id)
|
||||
return false;
|
||||
|
||||
$result = Db::GetInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `id_address`
|
||||
FROM '._DB_PREFIX_.'address
|
||||
WHERE `id_manufacturer` = '.(int)$this->id
|
||||
);
|
||||
|
||||
if (!$result)
|
||||
return false;
|
||||
|
||||
return $result['id_address'];
|
||||
}
|
||||
|
||||
@@ -175,22 +188,34 @@ class ManufacturerCore extends ObjectModel
|
||||
* @param boolean $get_nb_products [optional] return products numbers for each
|
||||
* @return array Manufacturers
|
||||
*/
|
||||
public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $id_group_shop = false)
|
||||
public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false,
|
||||
$n = false, $all_group = false, $id_group_shop = false)
|
||||
{
|
||||
if (!$id_lang)
|
||||
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
if (!$id_group_shop)
|
||||
$id_group_shop = (Context::getContext()->shop->id ? Shop::getGroupFromShop(Context::getContext()->shop->id) : Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT')));
|
||||
|
||||
$sql = 'SELECT m.*, ml.`description`';
|
||||
$sql .= 'FROM `'._DB_PREFIX_.'manufacturer_group_shop` mgs
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.id_manufacturer = mgs.id_manufacturer)
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.(int)$id_lang.')
|
||||
WHERE mgs.id_group_shop='.(int)$id_group_shop.($active ? ' AND m.`active` = 1' : '');
|
||||
$sql .= ' ORDER BY m.`name` ASC'.($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : '');
|
||||
if (!$id_group_shop)
|
||||
if (Context::getContext()->shop->id)
|
||||
$id_group_shop = Shop::getGroupFromShop(Context::getContext()->shop->id);
|
||||
else
|
||||
$id_group_shop = Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT'));
|
||||
|
||||
$sql = 'SELECT m.*, ml.`description`
|
||||
FROM `'._DB_PREFIX_.'manufacturer_group_shop` mgs
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.id_manufacturer = mgs.id_manufacturer)
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (
|
||||
m.`id_manufacturer` = ml.`id_manufacturer`
|
||||
AND ml.`id_lang` = '.(int)$id_lang.'
|
||||
)
|
||||
WHERE mgs.id_group_shop='.(int)$id_group_shop.
|
||||
($active ? ' AND m.`active` = 1' : '').'
|
||||
ORDER BY m.`name` ASC'.
|
||||
($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : '');
|
||||
|
||||
$manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
if ($manufacturers === false)
|
||||
return false;
|
||||
|
||||
if ($get_nb_products)
|
||||
{
|
||||
$sql_groups = '';
|
||||
@@ -199,28 +224,34 @@ class ManufacturerCore extends ObjectModel
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
}
|
||||
|
||||
foreach ($manufacturers as $key => $manufacturer)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`)
|
||||
WHERE m.`id_manufacturer` = '.(int)$manufacturer['id_manufacturer'].
|
||||
($active ? ' AND p.`active` = 1 ' : '').
|
||||
($all_group ? '' : ' AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
WHERE cg.`id_group` '.$sql_groups.')'));
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
|
||||
'SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`)
|
||||
WHERE m.`id_manufacturer` = '.(int)$manufacturer['id_manufacturer'].
|
||||
($active ? ' AND p.`active` = 1 ' : '').
|
||||
($all_group ? '' : ' AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||
WHERE cg.`id_group` '.$sql_groups.'
|
||||
)')
|
||||
);
|
||||
|
||||
$manufacturers[$key]['nb_products'] = count($result);
|
||||
}
|
||||
}
|
||||
|
||||
$total_manufacturers = count($manufacturers);
|
||||
for ($i = 0; $i < $total_manufacturers; $i++)
|
||||
if ((int)Configuration::get('PS_REWRITING_SETTINGS'))
|
||||
$manufacturers[$i]['link_rewrite'] = Tools::link_rewrite($manufacturers[$i]['name'], false);
|
||||
else
|
||||
$manufacturers[$i]['link_rewrite'] = 0;
|
||||
|
||||
return $manufacturers;
|
||||
}
|
||||
|
||||
@@ -240,17 +271,21 @@ class ManufacturerCore extends ObjectModel
|
||||
WHERE `id_manufacturer` = '.(int)$id_manufacturer.'
|
||||
AND `active` = 1'
|
||||
);
|
||||
|
||||
return self::$cacheName[$id_manufacturer];
|
||||
}
|
||||
|
||||
public static function getIdByName($name)
|
||||
{
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT `id_manufacturer`
|
||||
FROM `'._DB_PREFIX_.'manufacturer`
|
||||
WHERE `name` = \''.pSQL($name).'\'');
|
||||
SELECT `id_manufacturer`
|
||||
FROM `'._DB_PREFIX_.'manufacturer`
|
||||
WHERE `name` = \''.pSQL($name).'\''
|
||||
);
|
||||
|
||||
if (isset($result['id_manufacturer']))
|
||||
return (int)$result['id_manufacturer'];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -259,7 +294,8 @@ class ManufacturerCore extends ObjectModel
|
||||
return Tools::link_rewrite($this->name, false);
|
||||
}
|
||||
|
||||
public static function getProducts($id_manufacturer, $id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $active_category = true, Context $context = null)
|
||||
public static function getProducts($id_manufacturer, $id_lang, $p, $n, $order_by = null, $order_way = null,
|
||||
$get_total = false, $active = true, $active_category = true, Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
@@ -294,15 +330,22 @@ class ManufacturerCore extends ObjectModel
|
||||
($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
|
||||
WHERE cg.`id_group` '.$sql_groups.'
|
||||
)';
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
return (int)count($result);
|
||||
}
|
||||
|
||||
$sql = 'SELECT p.*, stock.out_of_stock, stock.quantity as quantity, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`link_rewrite`,
|
||||
pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name,
|
||||
tl.`name` AS tax_name, t.`rate`, DATEDIFF(p.`date_add`, DATE_SUB(NOW(),
|
||||
INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new,
|
||||
(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice
|
||||
$sql = 'SELECT p.*, stock.out_of_stock, stock.quantity as quantity, pa.`id_product_attribute`,
|
||||
pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`,
|
||||
pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`,
|
||||
DATEDIFF(
|
||||
p.`date_add`,
|
||||
DATE_SUB(
|
||||
NOW(),
|
||||
INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY
|
||||
)
|
||||
) > 0 AS new,
|
||||
(p.`price` * ((100 + (t.`rate`))/100)) AS orderprice
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.$context->shop->addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
|
||||
@@ -339,10 +382,13 @@ class ManufacturerCore extends ObjectModel
|
||||
LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n;
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
|
||||
if (!$result)
|
||||
return false;
|
||||
|
||||
if ($order_by == 'price')
|
||||
Tools::orderbyPrice($result, $order_way);
|
||||
|
||||
return Product::getProductsProperties($id_lang, $result);
|
||||
}
|
||||
|
||||
@@ -350,11 +396,15 @@ class ManufacturerCore extends ObjectModel
|
||||
{
|
||||
$sql = 'SELECT p.`id_product`, pl.`name`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('pl').'
|
||||
)
|
||||
WHERE p.`id_manufacturer` = '.(int)$this->id;
|
||||
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
/*
|
||||
* Specify if a manufacturer already in base
|
||||
*
|
||||
@@ -364,9 +414,10 @@ class ManufacturerCore extends ObjectModel
|
||||
public static function manufacturerExists($id_manufacturer)
|
||||
{
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT `id_manufacturer`
|
||||
FROM '._DB_PREFIX_.'manufacturer m
|
||||
WHERE m.`id_manufacturer` = '.(int)$id_manufacturer);
|
||||
SELECT `id_manufacturer`
|
||||
FROM '._DB_PREFIX_.'manufacturer m
|
||||
WHERE m.`id_manufacturer` = '.(int)$id_manufacturer
|
||||
);
|
||||
|
||||
return isset($row['id_manufacturer']);
|
||||
}
|
||||
@@ -374,41 +425,51 @@ class ManufacturerCore extends ObjectModel
|
||||
public function getAddresses($id_lang)
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT a.*, cl.name AS `country`, s.name AS `state`
|
||||
FROM `'._DB_PREFIX_.'address` AS a
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` AS cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'state` AS s ON (s.`id_state` = a.`id_state`)
|
||||
WHERE `id_manufacturer` = '.(int)$this->id.'
|
||||
AND a.`deleted` = 0');
|
||||
SELECT a.*, cl.name AS `country`, s.name AS `state`
|
||||
FROM `'._DB_PREFIX_.'address` AS a
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` AS cl ON (
|
||||
cl.`id_country` = a.`id_country`
|
||||
AND cl.`id_lang` = '.(int)$id_lang.'
|
||||
)
|
||||
LEFT JOIN `'._DB_PREFIX_.'state` AS s ON (s.`id_state` = a.`id_state`)
|
||||
WHERE `id_manufacturer` = '.(int)$this->id.'
|
||||
AND a.`deleted` = 0'
|
||||
);
|
||||
}
|
||||
|
||||
public function getWsAddresses()
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT a.id_address as id
|
||||
FROM `'._DB_PREFIX_.'address` AS a
|
||||
WHERE `id_manufacturer` = '.(int)$this->id.'
|
||||
AND a.`deleted` = 0');
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT a.id_address as id
|
||||
FROM `'._DB_PREFIX_.'address` AS a
|
||||
WHERE `id_manufacturer` = '.(int)$this->id.'
|
||||
AND a.`deleted` = 0'
|
||||
);
|
||||
}
|
||||
|
||||
public function setWsAddresses($id_addresses)
|
||||
{
|
||||
$ids = array();
|
||||
|
||||
foreach ($id_addresses as $id)
|
||||
$ids[] = (int)$id['id'];
|
||||
|
||||
$result1 = (Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'address`
|
||||
SET id_manufacturer = 0
|
||||
WHERE id_manufacturer = '.(int)$this->id.'
|
||||
AND deleted = 0') !== false);
|
||||
AND deleted = 0') !== false
|
||||
);
|
||||
|
||||
$result2 = true;
|
||||
if (count($ids))
|
||||
$result2 = (Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'address`
|
||||
SET id_customer = 0, id_supplier = 0, id_manufacturer = '.(int)$this->id.'
|
||||
WHERE id_address IN('.implode(',', $ids).')
|
||||
AND deleted = 0') !== false);
|
||||
UPDATE `'._DB_PREFIX_.'address`
|
||||
SET id_customer = 0, id_supplier = 0, id_manufacturer = '.(int)$this->id.'
|
||||
WHERE id_address IN('.implode(',', $ids).')
|
||||
AND deleted = 0') !== false
|
||||
);
|
||||
|
||||
return ($result1 && $result2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4212,10 +4212,12 @@ class ProductCore extends ObjectModel
|
||||
public function setCoverWs($id_image)
|
||||
{
|
||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'image`
|
||||
SET `cover` = 0 WHERE `id_product` = '.(int)$this->id.'
|
||||
');
|
||||
SET `cover` = 0 WHERE `id_product` = '.(int)$this->id.'
|
||||
');
|
||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'image`
|
||||
SET `cover` = 1 WHERE `id_product` = '.(int)$this->id.' AND `id_image` = '.(int)$id_image);
|
||||
SET `cover` = 1 WHERE `id_product` = '.(int)$this->id.' AND `id_image` = '.(int)$id_image
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user