// MERGE with 1.4 r7770
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7776 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+96
-40
@@ -263,7 +263,7 @@ class ProductCore extends ObjectModel
|
||||
'out_of_stock' => array('required' => true),
|
||||
'new' => array(),
|
||||
'cache_default_attribute' => array(),
|
||||
'id_default_image' => array('getter' => 'getCoverWs', 'setter' => false, 'xlink_resource' => array('resourceName' => 'images', 'subResourceName' => 'products')),
|
||||
'id_default_image' => array('getter' => 'getCoverWs', 'setter' => 'setCoverWs', 'xlink_resource' => array('resourceName' => 'images', 'subResourceName' => 'products')),
|
||||
'id_default_combination' => array('getter' => 'getWsDefaultCombination', 'setter' => 'setWsDefaultCombination', 'xlink_resource' => array('resourceName' => 'combinations')),
|
||||
'position_in_category' => array('getter' => 'getWsPositionInCategory', 'setter' => false),
|
||||
'manufacturer_name' => array('getter' => 'getWsManufacturerName', 'setter' => false),
|
||||
@@ -285,6 +285,10 @@ class ProductCore extends ObjectModel
|
||||
'id' => array('required' => true),
|
||||
'id_feature_value' => array('required' => true, 'xlink_resource' => 'product_feature_values'),
|
||||
)),
|
||||
'tags' => array('resource' => 'tag',
|
||||
'fields' => array(
|
||||
'id' => array('required' => true),
|
||||
)),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -486,7 +490,7 @@ class ProductCore extends ObjectModel
|
||||
$sizeof = sizeof($result);
|
||||
|
||||
for ($i = 0; $i < $sizeof; $i++)
|
||||
$return &= Db::getInstance()->Execute($sql='
|
||||
$return &= Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'category_product`
|
||||
SET `position` = '.(int)($i).'
|
||||
WHERE `id_category` = '.(int)($id_category).'
|
||||
@@ -507,7 +511,7 @@ class ProductCore extends ObjectModel
|
||||
' WHERE pa.default_on = 1 '
|
||||
.($minimumQuantity > 0 ? ' AND stock.quantity >= '.(int)$minimumQuantity : '').
|
||||
' AND pa.id_product = '.(int)$id_product;
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
@@ -516,17 +520,26 @@ class ProductCore extends ObjectModel
|
||||
.($minimumQuantity > 0 ? Product::sqlStock('pa', 'pa') : '').
|
||||
' WHERE pa.id_product = '.(int)$id_product
|
||||
.($minimumQuantity > 0 ? ' AND stock.quantity >= '.(int)$minimumQuantity : '');
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
$sql = 'SELECT id_product_attribute
|
||||
FROM '._DB_PREFIX_.'product_attribute
|
||||
WHERE `default_on` = 1
|
||||
AND id_product = '.(int)$id_product;
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
$sql = 'SELECT id_product_attribute
|
||||
FROM '._DB_PREFIX_.'product_attribute
|
||||
WHERE id_product = '.(int)$id_product;
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
$result = Db::getInstance()->getValue($sql);
|
||||
}
|
||||
return $result['id_product_attribute'];
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function updateDefaultAttribute($id_product)
|
||||
@@ -606,7 +619,8 @@ class ProductCore extends ObjectModel
|
||||
$currentCategories = $this->getCategories();
|
||||
|
||||
// for new categ, put product at last position
|
||||
$resCategNewPos = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql='SELECT id_category, MAX(position)+1 newPos
|
||||
$resCategNewPos = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT id_category, MAX(position)+1 newPos
|
||||
FROM `'._DB_PREFIX_.'category_product`
|
||||
WHERE `id_category` IN('.implode(',', array_map('intval', $categories)).')
|
||||
GROUP BY id_category');
|
||||
@@ -643,7 +657,7 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
if (empty($categories))
|
||||
return false;
|
||||
$positions = array();
|
||||
|
||||
// get max position in each categories
|
||||
$result = Db::getInstance()->ExecuteS('SELECT `id_category`
|
||||
FROM `'._DB_PREFIX_.'category_product`
|
||||
@@ -1091,18 +1105,9 @@ class ProductCore extends ObjectModel
|
||||
*/
|
||||
public function deleteAttachments()
|
||||
{
|
||||
$attachments = Db::getInstance()->ExecuteS('SELECT id_attachment FROM `'._DB_PREFIX_.'product_attachment` WHERE `id_product` = '.(int)($this->id));
|
||||
$result = true;
|
||||
foreach ($attachments AS $attachment)
|
||||
{
|
||||
$attachmentObj = new Attachment((int)($attachment['id_attachment']));
|
||||
if (Validate::isLoadedObject($attachmentObj))
|
||||
$result &= $attachmentObj->delete();
|
||||
return Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'product_attachment WHERE id_product = '.(int)($this->id));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete product customizations
|
||||
*
|
||||
@@ -1228,26 +1233,26 @@ class ProductCore extends ObjectModel
|
||||
public function deleteFeatures()
|
||||
{
|
||||
// List products features
|
||||
$result1 = Db::getInstance()->ExecuteS('
|
||||
$features = Db::getInstance()->ExecuteS('
|
||||
SELECT p.*, f.*
|
||||
FROM `'._DB_PREFIX_.'feature_product` as p
|
||||
LEFT JOIN `'._DB_PREFIX_.'feature_value` as f ON (f.`id_feature_value` = p.`id_feature_value`)
|
||||
WHERE `id_product` = '.(int)($this->id));
|
||||
foreach ($result1 as $tab)
|
||||
foreach ($features as $tab)
|
||||
// Delete product custom features
|
||||
if ($tab['custom']) {
|
||||
$result2 = Db::getInstance()->Execute('
|
||||
Db::getInstance()->Execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'feature_value`
|
||||
WHERE `id_feature_value` = '.(int)($tab['id_feature_value']));
|
||||
$result3 = Db::getInstance()->Execute('
|
||||
Db::getInstance()->Execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'feature_value_lang`
|
||||
WHERE `id_feature_value` = '.(int)($tab['id_feature_value']));
|
||||
}
|
||||
// Delete product features
|
||||
$result4 = Db::getInstance()->Execute('
|
||||
$result = Db::getInstance()->Execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'feature_product`
|
||||
WHERE `id_product` = '.(int)($this->id));
|
||||
return ($result4);
|
||||
return ($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1546,9 +1551,19 @@ class ProductCore extends ObjectModel
|
||||
WHERE `id_product` = '.(int)$id_product)
|
||||
)
|
||||
foreach ($row as $val)
|
||||
{
|
||||
$ret[] = $val['id_category'];
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function getProductCategoriesFull($id_product = '', $id_lang)
|
||||
{
|
||||
$ret = array();
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT cp.`id_category`, cl.`name`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'category_product` cp
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cp.`id_category` = cl.`id_category`)
|
||||
WHERE cp.`id_product` = '.(int)$id_product);
|
||||
foreach ($row as $val)
|
||||
$ret[$val['id_category']] = $val;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@@ -1573,7 +1588,7 @@ class ProductCore extends ObjectModel
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$sql = 'SELECT i.`cover`, i.`id_image`, il.`legend`
|
||||
$sql = 'SELECT i.`cover`, i.`id_image`, il.`legend`, i.`position`
|
||||
FROM `'._DB_PREFIX_.'image` i
|
||||
'.$context->shop->sqlAsso('image', 'i').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
@@ -1611,7 +1626,7 @@ class ProductCore extends ObjectModel
|
||||
* @param boolean $only_reduc Returns only the reduction amount
|
||||
* @param boolean $usereduc Set if the returned amount will include reduction
|
||||
* @param integer $quantity Required for quantity discount application (default value: 1)
|
||||
* @param boolean $forceAssociatedTax Force to apply the associated tax. Only works when the parameter $usetax is true
|
||||
* @param boolean $forceAssociatedTax DEPRECATED - NOT USED Force to apply the associated tax. Only works when the parameter $usetax is true
|
||||
* @param integer $id_customer Customer ID (for customer group reduction)
|
||||
* @param integer $id_cart Cart ID. Required when the cookie is not accessible (e.g., inside a payment module, a cron task...)
|
||||
* @param integer $id_address Customer address ID. Required for price (tax included) calculation regarding the guest localization
|
||||
@@ -1726,8 +1741,6 @@ class ProductCore extends ObjectModel
|
||||
else
|
||||
$product_attribute_label = ($id_product_attribute === false ? 'false' : $id_product_attribute);
|
||||
$cacheId = $id_product.'-'.$id_shop.'-'.$id_currency.'-'.$id_country.'-'.$id_state.'-'.$id_county.'-'.$id_group.'-'.$quantity.'-'.$product_attribute_label.'-'.($use_tax?'1':'0').'-'.$decimals.'-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0').'-'.$with_ecotax;
|
||||
// Cache for specific prices
|
||||
$cacheId3 = $id_product.'-'.$id_shop.'-'.$id_currency.'-'.$id_country.'-'.$id_group.'-'.$quantity;
|
||||
|
||||
// reference parameter is filled before any returns
|
||||
$specific_price = SpecificPrice::getSpecificPrice((int)($id_product), $id_shop, $id_currency, $id_country, $id_group, $quantity);
|
||||
@@ -1802,7 +1815,7 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
$ecotax = $result['ecotax'];
|
||||
if (isset($result['attribute_ecotax']) && $result['attribute_ecotax'] > 0)
|
||||
$ecotax = $result['ecotax'];
|
||||
$ecotax = $result['attribute_ecotax'];
|
||||
|
||||
if ($id_currency)
|
||||
$ecotax = Tools::convertPrice($ecotax, $id_currency);
|
||||
@@ -1911,6 +1924,13 @@ class ProductCore extends ObjectModel
|
||||
return Tools::displayPrice($params['price'], $smarty->ps_currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert price with currency
|
||||
*
|
||||
* @param array $params
|
||||
* @param object $smarty DEPRECATED
|
||||
* @return Ambigous <string, mixed, Ambigous <number, string>>
|
||||
*/
|
||||
static function convertPriceWithCurrency($params, &$smarty)
|
||||
{
|
||||
if (!isset($params['convert']))
|
||||
@@ -1923,6 +1943,13 @@ class ProductCore extends ObjectModel
|
||||
return Tools::displayPrice($params['p'], $smarty->ps_currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display WT price with currency
|
||||
*
|
||||
* @param array $params
|
||||
* @param object DEPRECATED $smarty
|
||||
* @return Ambigous <string, mixed, Ambigous <number, string>>
|
||||
*/
|
||||
static function displayWtPriceWithCurrency($params, &$smarty)
|
||||
{
|
||||
return Tools::displayPrice($params['price'], $params['currency'], false);
|
||||
@@ -2426,7 +2453,7 @@ class ProductCore extends ObjectModel
|
||||
return false;
|
||||
|
||||
$resultsArray = array();
|
||||
foreach ($result AS $k => $row)
|
||||
foreach ($result AS $row)
|
||||
{
|
||||
$row['price'] = Product::getPriceStatic($row['id_product'], true, NULL, 2);
|
||||
$row['quantity'] = Product::getQuantity($row['id_product'], NULL, $row['cache_is_pack']);
|
||||
@@ -3040,22 +3067,19 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
if (!$id_customer)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT ctg.`id_group`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`)
|
||||
WHERE cp.`id_product` = '.(int)($this->id).' AND ctg.`id_group` = 1');
|
||||
WHERE cp.`id_product` = '.(int)$this->id.' AND ctg.`id_group` = 1');
|
||||
} else {
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT cg.`id_group`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`)
|
||||
INNER JOIN `'._DB_PREFIX_.'customer_group` cg ON (cg.`id_group` = ctg.`id_group`)
|
||||
WHERE cp.`id_product` = '.(int)($this->id).' AND cg.`id_customer` = '.(int)($id_customer));
|
||||
WHERE cp.`id_product` = '.(int)$this->id.' AND cg.`id_customer` = '.(int)$id_customer);
|
||||
}
|
||||
if ($result AND isset($result['id_group']) AND $result['id_group'])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3282,7 +3306,7 @@ class ProductCore extends ObjectModel
|
||||
|
||||
// Delete rows
|
||||
if (count($toDelete) > 0)
|
||||
$result = Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product_attribute` IN ('.implode(',', $toDelete).')');
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product_attribute` IN ('.implode(',', $toDelete).')');
|
||||
|
||||
foreach ($toAdd as $id)
|
||||
{
|
||||
@@ -3336,6 +3360,21 @@ class ProductCore extends ObjectModel
|
||||
return $result['id_image'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Webservice setter : set virtual field id_default_image in category
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setCoverWs($id_image)
|
||||
{
|
||||
Db::getInstance()->ExecuteS('UPDATE `'._DB_PREFIX_.'image`
|
||||
SET `cover` = 0 WHERE `id_product` = '.(int)($this->id).'
|
||||
');
|
||||
Db::getInstance()->ExecuteS('UPDATE `'._DB_PREFIX_.'image`
|
||||
SET `cover` = 1 WHERE `id_product` = '.(int)($this->id).' AND `id_image` = '.(int)$id_image);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Webservice getter : get image ids of current product for association
|
||||
*
|
||||
@@ -3350,8 +3389,25 @@ class ProductCore extends ObjectModel
|
||||
ORDER BY `position`');
|
||||
}
|
||||
|
||||
public function getWsTags()
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT `id_tag` as id
|
||||
FROM `'._DB_PREFIX_.'product_tag`
|
||||
WHERE `id_product` = '.(int)($this->id));
|
||||
}
|
||||
|
||||
|
||||
public function getWsManufacturerName()
|
||||
{
|
||||
return Manufacturer::getNameById((int)$this->id_manufacturer);
|
||||
}
|
||||
|
||||
public static function resetEcoTax()
|
||||
{
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'product`
|
||||
SET ecotax = 0
|
||||
');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user