// Fix shipping cost for virtual products
This commit is contained in:
+9
-23
@@ -371,7 +371,7 @@ class CartCore extends ObjectModel
|
||||
$sql = new DbQuery();
|
||||
|
||||
// Build SELECT
|
||||
$sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`,
|
||||
$sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
|
||||
pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`,
|
||||
p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`, p.`price`, p.`weight`, p.`width`, p.`height`, p.`depth`, p.`out_of_stock`,
|
||||
p.`active`, p.`date_add`, p.`date_upd`, t.`id_tax`, tl.`name` AS tax, t.`rate`, stock.quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
|
||||
@@ -428,6 +428,7 @@ class CartCore extends ObjectModel
|
||||
else
|
||||
$sql->select('p.`reference` AS reference, p.`supplier_reference` AS supplier_reference, p.`ean13`, p.`upc` AS upc, p.`minimal_quantity` AS minimal_quantity');
|
||||
|
||||
|
||||
$result = Db::getInstance()->ExecuteS($sql);
|
||||
|
||||
// Reset the cache before the following return, or else an empty cart will add dozens of queries
|
||||
@@ -1528,9 +1529,8 @@ class CartCore extends ObjectModel
|
||||
* @return boolean true if is a virtual cart or false
|
||||
*
|
||||
*/
|
||||
public function isVirtualCart()
|
||||
public function isVirtualCart($strict = false)
|
||||
{
|
||||
$prod = array();
|
||||
if (!ProductDownload::isFeatureActive())
|
||||
return false;
|
||||
|
||||
@@ -1539,33 +1539,19 @@ class CartCore extends ObjectModel
|
||||
$products = $this->getProducts();
|
||||
if (!sizeof($products))
|
||||
return false;
|
||||
|
||||
|
||||
$is_virtual = 1;
|
||||
foreach ($products AS $product)
|
||||
{
|
||||
$prod[] = (int) $product['id_product'];
|
||||
if (empty($product['is_virtual']))
|
||||
$is_virtual = 0;
|
||||
}
|
||||
|
||||
$unique_product = array_unique($prod);
|
||||
|
||||
$list = '';
|
||||
foreach ($unique_product AS $product)
|
||||
{
|
||||
$list .= (int)($product).',';
|
||||
}
|
||||
$list = rtrim($list, ',');
|
||||
|
||||
$n = (int)Db::getInstance()->getValue('
|
||||
SELECT COUNT(`id_product_download`) n
|
||||
FROM `'._DB_PREFIX_.'product_download`
|
||||
WHERE `id_product` IN ('.pSQL($list).')
|
||||
AND `active` = 1');
|
||||
|
||||
self::$_isVirtualCart[$this->id] = ($n == sizeof($products));
|
||||
self::$_isVirtualCart[$this->id] = (int) $is_virtual;
|
||||
}
|
||||
|
||||
return self::$_isVirtualCart[$this->id];
|
||||
}
|
||||
|
||||
|
||||
public static function getCartByOrderId($id_order)
|
||||
{
|
||||
if ($id_cart = self::getCartIdByOrderId($id_order))
|
||||
|
||||
@@ -161,7 +161,7 @@ class OrderHistoryCore extends ObjectModel
|
||||
$assign = array();
|
||||
foreach ($virtualProducts AS $key => $virtualProduct)
|
||||
{
|
||||
$id_product_download = ProductDownload::getIdFromIdAttibute($virtualProduct['product_id'], $virtualProduct['product_attribute_id']);
|
||||
$id_product_download = ProductDownload::getIdFromIdAttribute($virtualProduct['product_id'], $virtualProduct['product_attribute_id']);
|
||||
$product_download = new ProductDownload($id_product_download);
|
||||
// If this virtual item has an associated file, we'll provide the link to download the file in the email
|
||||
if ($product_download->display_filename != '')
|
||||
|
||||
+5
-1
@@ -196,7 +196,8 @@ class ProductCore extends ObjectModel
|
||||
protected $langMultiShop = true;
|
||||
|
||||
public $cache_is_pack;
|
||||
public $cache_has_attachments;
|
||||
public $cache_has_attachments;
|
||||
public $is_virtual;
|
||||
public $cache_default_attribute;
|
||||
|
||||
public static $_taxCalculationMethod = PS_TAX_EXC;
|
||||
@@ -252,6 +253,7 @@ class ProductCore extends ObjectModel
|
||||
'upc' => 'isUpc',
|
||||
'indexed' => 'isBool',
|
||||
'cache_is_pack' => 'isBool',
|
||||
'is_virtual' => 'isBool',
|
||||
'cache_has_attachments' => 'isBool'
|
||||
);
|
||||
protected $fieldsRequiredLang = array('link_rewrite', 'name');
|
||||
@@ -381,6 +383,7 @@ class ProductCore extends ObjectModel
|
||||
$fields['indexed'] = 0; // Reset indexation every times
|
||||
$fields['cache_is_pack'] = (int)($this->cache_is_pack);
|
||||
$fields['cache_has_attachments'] = (int)($this->cache_has_attachments);
|
||||
$fields['is_virtual'] = (int)($this->is_virtual);
|
||||
$fields['cache_default_attribute'] = (int)($this->cache_default_attribute);
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
$fields['date_upd'] = pSQL($this->date_upd);
|
||||
@@ -2867,6 +2870,7 @@ class ProductCore extends ObjectModel
|
||||
$row['id_image'] = Product::defineProductImage($row, $id_lang);
|
||||
$row['features'] = Product::getFrontFeaturesStatic((int)$id_lang, $row['id_product']);
|
||||
$row['attachments'] = ((!isset($row['cache_has_attachments']) OR $row['cache_has_attachments']) ? Product::getAttachmentsStatic((int)($id_lang), $row['id_product']) : array());
|
||||
$row['virtual'] = ((!isset($row['is_virtual']) OR $row['is_virtual']) ? 1 : 0);
|
||||
|
||||
// Pack management
|
||||
$row['pack'] = (!isset($row['cache_is_pack']) ? Pack::isPack($row['id_product']) : (int)$row['cache_is_pack']);
|
||||
|
||||
@@ -198,7 +198,10 @@ class ProductDownloadCore extends ObjectModel
|
||||
self::$_productIds[$id_product] = (int)Db::getInstance()->getValue('
|
||||
SELECT `id_product_download`
|
||||
FROM `'._DB_PREFIX_.'product_download`
|
||||
WHERE `id_product` = '.(int)$id_product.' AND `active` = 1');
|
||||
WHERE `id_product` = '.(int)$id_product.'
|
||||
AND `active` = 1
|
||||
ORDER BY `id_product_download` DESC');
|
||||
|
||||
return self::$_productIds[$id_product];
|
||||
}
|
||||
|
||||
@@ -208,7 +211,7 @@ class ProductDownloadCore extends ObjectModel
|
||||
* @param int $id_product Product the id
|
||||
* @return integer Product the id for this virtual product
|
||||
*/
|
||||
public static function getIdFromIdAttibute($id_product, $id_product_attribute)
|
||||
public static function getIdFromIdAttribute($id_product, $id_product_attribute)
|
||||
{
|
||||
if (!self::isFeatureActive())
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user