// Fix shipping cost for virtual products
This commit is contained in:
@@ -149,7 +149,7 @@ class AdminProducts extends AdminTab
|
||||
|
||||
public function deleteVirtualProduct()
|
||||
{
|
||||
if (!($id_product_download = ProductDownload::getIdFromIdProduct(intval(Tools::getValue('id_product')))))
|
||||
if (!($id_product_download = ProductDownload::getIdFromIdProduct((int)Tools::getValue('id_product'))))
|
||||
return false;
|
||||
$productDownload = new ProductDownload((int)($id_product_download));
|
||||
return $productDownload->deleteFile();
|
||||
@@ -157,7 +157,7 @@ class AdminProducts extends AdminTab
|
||||
|
||||
public function deleteVirtualProductAttribute()
|
||||
{
|
||||
if (!($id_product_download = ProductDownload::getIdFromIdAttibute((int) Tools::getValue('id_product_attribute'))))
|
||||
if (!($id_product_download = ProductDownload::getIdFromIdAttribute((int)Tools::getValue('id_product'), (int) Tools::getValue('id_product_attribute'))))
|
||||
return false;
|
||||
$productDownload = new ProductDownload((int)($id_product_download));
|
||||
return $productDownload->deleteFile();
|
||||
@@ -585,7 +585,7 @@ class AdminProducts extends AdminTab
|
||||
{
|
||||
$product->deleteAttributeCombinaison(Tools::getValue('id_product_attribute'));
|
||||
|
||||
$id_product_download = ProductDownload::getIdFromIdAttibute((int) Tools::getValue('id_product_attribute'));
|
||||
$id_product_download = ProductDownload::getIdFromIdAttribute((int) $id_product, (int) Tools::getValue('id_product_attribute'));
|
||||
if ($id_product_download)
|
||||
{
|
||||
$productDownload = new ProductDownload((int) $id_product_download);
|
||||
@@ -1260,30 +1260,12 @@ class AdminProducts extends AdminTab
|
||||
*/
|
||||
public function updateDownloadProduct($product, $edit = 0, $id_product_attribute = null)
|
||||
{
|
||||
$filename = '';
|
||||
$is_virtual_file = 0;
|
||||
$id_product_download = 0;
|
||||
|
||||
$is_shareable = 0;
|
||||
$virtual_product_name = '';
|
||||
$virtual_product_nb_days = 0;
|
||||
$virtual_product_filename = '';
|
||||
$virtual_product_nb_downloable = 0;
|
||||
$virtual_product_expiration_date = '';
|
||||
|
||||
$is_shareable_attribute = 0;
|
||||
$virtual_product_name_attribute = '';
|
||||
$virtual_product_nb_days_attribute = 0;
|
||||
$virtual_product_filename_attribute = '';
|
||||
$virtual_product_nb_downloable_attribute = 0;
|
||||
$virtual_product_expiration_date_attribute = '';
|
||||
|
||||
$is_virtual_file = (int) Tools::getValue('is_virtual_file');
|
||||
|
||||
/* add or update a virtual product */
|
||||
if (Tools::getValue('is_virtual_good') == 'true')
|
||||
{
|
||||
if (!Tools::getValue('virtual_product_id') && !Tools::getValue('virtual_product_name_attribute') && !empty($is_virtual_file))
|
||||
if (!Tools::getValue('virtual_product_name') && !Tools::getValue('virtual_product_name_attribute') && !empty($is_virtual_file))
|
||||
{
|
||||
if (!Tools::getValue('virtual_product_name'))
|
||||
{
|
||||
@@ -1302,22 +1284,26 @@ class AdminProducts extends AdminTab
|
||||
|
||||
if (Tools::getValue('virtual_product_nb_days') === false && Tools::getValue('virtual_product_nb_days_attribute') === false && !empty($is_virtual_file))
|
||||
{
|
||||
if (!Tools::getValue('virtual_product_name'))
|
||||
if (!Tools::getValue('virtual_product_nb_days'))
|
||||
{
|
||||
if (!Tools::getValue('virtual_product_name_attribute'))
|
||||
if (!Tools::getValue('virtual_product_nb_days_attribute'))
|
||||
{
|
||||
$this->_errors[] = $this->l('the field').' <b>'.$this->l('number of days attribute').'</b> '.$this->l('is required');
|
||||
return false;
|
||||
if (!empty($edit) && !empty($id_product_attribute))
|
||||
{
|
||||
$this->_errors[] = $this->l('the field').' <b>'.$this->l('number of days attribute').'</b> '.$this->l('is required');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (!empty($id_product_attribute))
|
||||
{
|
||||
$this->_errors[] = $this->l('the field').' <b>'.$this->l('number of days').'</b> '.$this->l('is required');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Tools::getValue('virtual_product_expiration_date') AND !Validate::isDate(Tools::getValue('virtual_product_expiration_date') && !empty($is_virtual_file))
|
||||
&& Tools::getValue('virtual_product_expiration_date_attribute') AND !Validate::isDate(Tools::getValue('virtual_product_expiration_date_attribute')))
|
||||
}
|
||||
|
||||
if (Tools::getValue('virtual_product_expiration_date') && !Validate::isDate(Tools::getValue('virtual_product_expiration_date') && !empty($is_virtual_file))
|
||||
&& Tools::getValue('virtual_product_expiration_date_attribute') && !Validate::isDate(Tools::getValue('virtual_product_expiration_date_attribute')))
|
||||
{
|
||||
if (!Tools::getValue('virtual_product_expiration_date'))
|
||||
{
|
||||
@@ -1326,7 +1312,7 @@ class AdminProducts extends AdminTab
|
||||
$this->_errors[] = $this->l('the field').' <b>'.$this->l('expiration date attribute').'</b> '.$this->l('is required');
|
||||
return false;
|
||||
}
|
||||
else
|
||||
else if (!empty($id_product_attribute))
|
||||
{
|
||||
$this->_errors[] = $this->l('the field').' <b>'.$this->l('expiration date').'</b> '.$this->l('is not valid');
|
||||
return false;
|
||||
@@ -1344,7 +1330,7 @@ class AdminProducts extends AdminTab
|
||||
// Trick's
|
||||
if ($edit == 1)
|
||||
{
|
||||
$id_product_download_attibute = ProductDownload::getIdFromIdAttibute($id_product_attribute);
|
||||
$id_product_download_attibute = ProductDownload::getIdFromIdAttribute((int) $product->id, $id_product_attribute);
|
||||
$id_product_download = ($id_product_download_attibute) ? (int) $id_product_download_attibute : (int) Tools::getValue('virtual_product_id');
|
||||
}
|
||||
|
||||
@@ -1404,7 +1390,7 @@ class AdminProducts extends AdminTab
|
||||
/* unactive download product if checkbox not checked */
|
||||
if ($edit == 1)
|
||||
{
|
||||
$id_product_download_attibute = ProductDownload::getIdFromIdAttibute($id_product_attribute);
|
||||
$id_product_download_attibute = ProductDownload::getIdFromIdAttribute((int) $product->id, $id_product_attribute);
|
||||
$id_product_download = ($id_product_download_attibute) ? (int) $id_product_download_attibute : (int) Tools::getValue('virtual_product_id');
|
||||
}
|
||||
else
|
||||
@@ -2302,15 +2288,21 @@ class AdminProducts extends AdminTab
|
||||
//]]>
|
||||
</script>
|
||||
<?php
|
||||
|
||||
if(($productDownload->id OR Tools::getValue('is_virtual_good')=='true') AND $productDownload->active)
|
||||
$check = 'checked="checked"';
|
||||
|
||||
|
||||
if(!$productDownload->id OR !$productDownload->active)
|
||||
$hidden = 'style="display:none;"';
|
||||
|
||||
$cache_default_attribute = $this->getFieldValue($obj, 'cache_default_attribute');
|
||||
|
||||
$cache_default_attribute = (int) $this->getFieldValue($obj, 'cache_default_attribute');
|
||||
$is_virtual = (int) $this->getFieldValue($obj, 'is_virtual');
|
||||
|
||||
if($is_virtual && $productDownload->active)
|
||||
$check = 'checked="checked"';
|
||||
|
||||
if($is_virtual)
|
||||
$virtual = 1;
|
||||
else
|
||||
$virtual = 0;
|
||||
|
||||
echo '
|
||||
<div class="tab-page" id="step1">
|
||||
<h4 class="tab">1. '.$this->l('Info.').'</h4>
|
||||
@@ -2625,8 +2617,8 @@ class AdminProducts extends AdminTab
|
||||
var newLabel = \''.$this->l('New label').'\';
|
||||
var choose_language = \''.$this->l('Choose language:').'\';
|
||||
var required = \''.$this->l('required').'\';
|
||||
var customizationUploadableFileNumber = '.(int)($this->getFieldValue($obj, 'uploadable_files')).';
|
||||
var customizationTextFieldNumber = '.(int)($this->getFieldValue($obj, 'text_fields')).';
|
||||
var customizationUploadableFileNumber = '.(int) $this->getFieldValue($obj, 'uploadable_files').';
|
||||
var customizationTextFieldNumber = '.(int) $this->getFieldValue($obj, 'text_fields').';
|
||||
var uploadableFileLabel = 0;
|
||||
var textFieldLabel = 0;
|
||||
</script>
|
||||
@@ -2636,28 +2628,21 @@ class AdminProducts extends AdminTab
|
||||
<p><input type="checkbox" id="is_virtual_good" name="is_virtual_good" value="true" onclick="toggleVirtualProduct(this);" '.$check.' />
|
||||
<label for="is_virtual_good" class="t bold" style="color: black;">'.$this->l('Is this a virtual product?').'</label></p>
|
||||
<div id="virtual_good" '.$hidden.'>
|
||||
|
||||
<input type="hidden" id="is_virtual" name="is_virtual" value="'.$virtual.'" />
|
||||
<br/>'.$this->l('Does this product has an associated file ?').'<br/>';
|
||||
|
||||
$exists_file = realpath(_PS_DOWNLOAD_DIR_).'/'.$productDownload->filename;
|
||||
|
||||
if ($productDownload->id && file_exists($exists_file) || !empty($productDownload->display_filename))
|
||||
{
|
||||
// todo gérer le is_virtual avec la valeur du produit
|
||||
$exists_file = realpath(_PS_DOWNLOAD_DIR_).'/'.$productDownload->filename;
|
||||
|
||||
if ($productDownload->id && !empty($cache_default_attribute) && !empty($productDownload->display_filename))
|
||||
{
|
||||
$check_yes = 'checked="checked"';
|
||||
$check_no = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($productDownload->id && !empty($cache_default_attribute))
|
||||
{
|
||||
$check_yes = 'checked="checked"';
|
||||
$check_no = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$check_yes = '';
|
||||
$check_no = 'checked="checked"';
|
||||
}
|
||||
$check_yes = '';
|
||||
$check_no = 'checked="checked"';
|
||||
}
|
||||
|
||||
echo '<input type="radio" value="1" id="virtual_good_file_1" name="is_virtual_file" '.$check_yes.'/>'. $this->l('Yes').'
|
||||
@@ -2814,6 +2799,17 @@ class AdminProducts extends AdminTab
|
||||
$("#virtual_good_attributes").hide();
|
||||
$("#is_virtual_file_product").hide();
|
||||
}
|
||||
});
|
||||
|
||||
$("input[name=is_virtual_good]").live("change", function() {
|
||||
if($(this).attr("checked"))
|
||||
{
|
||||
$("#is_virtual").val(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#is_virtual").val(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -3712,7 +3708,7 @@ class AdminProducts extends AdminTab
|
||||
$productDownload = new ProductDownload();
|
||||
$id_product_download = (int) $productDownload->getIdFromIdProduct($this->getFieldValue($obj, 'id'));
|
||||
if (!empty($id_product_download))
|
||||
$productDownload = new ProductDownload($id_product_download);
|
||||
$productDownload = new ProductDownload($id_product_download);
|
||||
|
||||
$images = Image::getImages($this->context->language->id, $obj->id);
|
||||
if ($obj->id)
|
||||
@@ -3999,7 +3995,8 @@ class AdminProducts extends AdminTab
|
||||
<th>'.$this->l('UPC').'</th>
|
||||
<th class="center">'.$this->l('Quantity').'</th>';
|
||||
|
||||
if ($id_product_download && !empty($productDownload->filename))
|
||||
|
||||
if ($id_product_download && !empty($productDownload->display_filename))
|
||||
{
|
||||
echo '
|
||||
<th class="center virtual_header">'.$this->l('Filename').'</th>
|
||||
@@ -4061,7 +4058,7 @@ class AdminProducts extends AdminTab
|
||||
$attrImage = $product_attribute['id_image'] ? new Image($product_attribute['id_image']) : false;
|
||||
$available_date = ($product_attribute['available_date'] != 0) ? date('Y-m-d', strtotime($product_attribute['available_date'])) : '0000-00-00';
|
||||
|
||||
$id_product_download = $productDownload->getIdFromIdAttibute((int) $id_product_attribute);
|
||||
$id_product_download = $productDownload->getIdFromIdAttribute((int) $obj->id, (int) $id_product_attribute);
|
||||
if ($id_product_download)
|
||||
$productDownload = new ProductDownload($id_product_download);
|
||||
|
||||
|
||||
+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;
|
||||
|
||||
@@ -1214,6 +1214,7 @@ CREATE TABLE `PREFIX_product` (
|
||||
`indexed` tinyint(1) NOT NULL default '0',
|
||||
`cache_is_pack` tinyint(1) NOT NULL default '0',
|
||||
`cache_has_attachments` tinyint(1) NOT NULL default '0',
|
||||
`is_virtual` tinyint(1) NOT NULL default '0',
|
||||
`cache_default_attribute` int(10) unsigned default NULL,
|
||||
`date_add` datetime NOT NULL,
|
||||
`date_upd` datetime NOT NULL,
|
||||
|
||||
@@ -173,4 +173,6 @@ CREATE TABLE IF NOT EXISTS `PREFIX_request_sql` (
|
||||
|
||||
|
||||
ALTER TABLE `PREFIX_carrier` ADD COLUMN `id_reference` int(10) NOT NULL AFTER `id_carrier`;
|
||||
UPDATE `PREFIX_carrier` SET id_reference = id_carrier;
|
||||
UPDATE `PREFIX_carrier` SET id_reference = id_carrier;
|
||||
|
||||
ALTER TABLE `PREFIX_product` ADD `is_virtual` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `cache_has_attachments`
|
||||
Reference in New Issue
Block a user