Validation, help and more
This commit is contained in:
parent
21cd725307
commit
987cd037d7
@ -1,8 +1,19 @@
|
||||
|
||||
# Install
|
||||
Install
|
||||
=======
|
||||
|
||||
- Install Db table
|
||||
- Some Core and Template Files must be changed (see install dir)
|
||||
- Modify ps_cart_product
|
||||
ALTER TABLE `ps_cart_product` ADD `id_configurator` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `id_product_attribute`;
|
||||
ALTER TABLE `ps_cart_product` DROP PRIMARY KEY, ADD PRIMARY KEY (`id_cart`, `id_product`, `id_product_attribute`, `id_address_delivery`, `id_configurator`) USING BTREE;
|
||||
- Modify ps_order_detail
|
||||
ALTER TABLE `ps_order_detail` ADD `id_configurator` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `product_price`;
|
||||
|
||||
# Documentation
|
||||
Documentation
|
||||
=============
|
||||
|
||||
* Disable ajax cart
|
||||
|
||||
* Configuration d'une liste d'options (group)
|
||||
- type, reference, name
|
||||
@ -14,7 +25,6 @@
|
||||
- Group : required, position
|
||||
- Impact : name with price
|
||||
|
||||
|
||||
Lors de la sélection du choix des options pour le panier
|
||||
Group avec texte libre (text, date)
|
||||
optgroup-{id} = value
|
||||
@ -26,23 +36,10 @@ Attention les valeurs du groupes peuvent être multiples
|
||||
|
||||
Désactivé le panier en ajax
|
||||
Attention même id_cart - id_product mais options différentes
|
||||
Associations ps_cart_product <= id_configurator
|
||||
ALTER TABLE `ps_cart_product` ADD `id_configurator` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `id_product_attribute`;
|
||||
+ ajouter id_configurator a PRIMARY KEY
|
||||
|
||||
|
||||
Associations ps_order_detail <= id_configurator
|
||||
|
||||
Table stockage des options id_configurator | id_product | id_product_configurator_opt_group | value | price
|
||||
|
||||
|
||||
|
||||
Modifier l'Adapter
|
||||
Adapter_ProductPriceCalculator
|
||||
|
||||
* Panier
|
||||
- Stockage des valeurs selectionnées dans une table
|
||||
id + id_option + value + price
|
||||
|
||||
* TODO
|
||||
- Afficher le détail des options choisies dans le panier, dans la commande
|
||||
- Question : dans le stockage des options quid des éléments text, date, fichier
|
||||
|
@ -7,6 +7,7 @@ require_once dirname(__FILE__).'/classes/ConfiguratorOptGroup.php';
|
||||
require_once dirname(__FILE__).'/classes/ConfiguratorOpt.php';
|
||||
require_once dirname(__FILE__).'/classes/ProductConfiguratorOptGroup.php';
|
||||
require_once dirname(__FILE__).'/classes/ProductConfiguratorOptImpact.php';
|
||||
require_once dirname(__FILE__).'/classes/ConfiguratorStorage.php';
|
||||
|
||||
class AntadisConfigurator extends Module
|
||||
{
|
||||
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
class ConfiguratorStorage extends ObjectModel
|
||||
{
|
||||
/**
|
||||
* Product with configuration
|
||||
* @param int $id_product
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hasConfiguratorOpt($id_product)
|
||||
{
|
||||
$result = Db::getInstance()->getValue('
|
||||
SELECT count(*) AS nb
|
||||
FROM `'._DB_PREFIX_.'product_configurator_opt_group` pcog,
|
||||
`'._DB_PREFIX_.'configurator_opt_group` cog
|
||||
WHERE pcog.`id_product` = '.(int)$id_product.'
|
||||
AND cog.`id_configurator_opt_group` = pcog.`id_configurator_opt_group`');
|
||||
|
||||
return ( $result > 0 ? true : false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne les groupes options
|
||||
* @param int $id_product
|
||||
* @return array|false|NULL|mysqli_result|PDOStatement|resource
|
||||
*/
|
||||
public static function getConfiguratorOptGroup($id_product)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT pcog.*, col.`name`, cog.`type`
|
||||
FROM `'._DB_PREFIX_.'product_configurator_opt_group` pcog,
|
||||
`'._DB_PREFIX_.'configurator_opt_group` cog,
|
||||
`'._DB_PREFIX_.'configurator_opt_group_lang` col
|
||||
WHERE pcog.`id_product` = '.(int)$id_product.'
|
||||
AND cog.`id_configurator_opt_group` = col.`id_configurator_opt_group`
|
||||
AND pcog.`id_configurator_opt_group` = col.`id_configurator_opt_group`
|
||||
AND col.`id_lang` = '.(int)$context->language->id.'
|
||||
ORDER BY pcog.`position` ASC');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne les impacts
|
||||
* @param int $id_product
|
||||
* @return array|false|NULL|mysqli_result|PDOStatement|resource
|
||||
*/
|
||||
public static function getConfiguratorOptImpact($id_product)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT pcoi.`id_product_configurator_opt_impact`, pcoi.`id_product_configurator_opt_group`, pcoi.`id_configurator_opt`, col.`name`, pcoi.`price`, co.`position`
|
||||
FROM `'._DB_PREFIX_.'product_configurator_opt_impact` pcoi
|
||||
LEFT JOIN `'._DB_PREFIX_.'configurator_opt` co ON co.`id_configurator_opt` = pcoi.`id_configurator_opt`
|
||||
LEFT JOIN `'._DB_PREFIX_.'configurator_opt_lang` col
|
||||
ON (col.`id_configurator_opt` = pcoi.`id_configurator_opt` AND col.`id_lang` = '.(int)$context->language->id.')
|
||||
WHERE pcoi.`id_product` = '.(int)$id_product.'
|
||||
ORDER BY co.`position` ASC');
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@ -16,13 +16,13 @@ class AdminAntadisConfiguratorController extends ModuleAdminController
|
||||
'width' => 25
|
||||
),
|
||||
'name' => array(
|
||||
'title' => $this->l('Nom')
|
||||
'title' => $this->l('Nom'),
|
||||
),
|
||||
'type' => array(
|
||||
'title' => $this->l('Type')
|
||||
'title' => $this->l('Type'),
|
||||
),
|
||||
'reference' => array(
|
||||
'title' => $this->l('Reference')
|
||||
'title' => $this->l('Reference'),
|
||||
),
|
||||
);
|
||||
|
||||
@ -267,8 +267,20 @@ class AdminAntadisConfiguratorController extends ModuleAdminController
|
||||
$this->fields_form = array(
|
||||
'legend' => array('title' => $this->l('Add / Edit')),
|
||||
'input' => array(
|
||||
array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'required' => true, 'lang' => true),
|
||||
array('type' => 'select', 'label' => $this->l('Type'), 'name' => 'type', 'required' => true,
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Name'),
|
||||
'hint' => $this->l("Nom du groupe de l'option à afficher."),
|
||||
'name' => 'name',
|
||||
'required' => true,
|
||||
'lang' => true
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Type'),
|
||||
'hint' => $this->l("Type de l'option pour générer le formulaire de sélection sur la page produit."),
|
||||
'name' => 'type',
|
||||
'required' => true,
|
||||
'options' => array(
|
||||
'id' => 'id',
|
||||
'name' => 'name',
|
||||
@ -281,7 +293,13 @@ class AdminAntadisConfiguratorController extends ModuleAdminController
|
||||
),
|
||||
),
|
||||
),
|
||||
array('type' => 'text', 'label' => $this->l('Reference'), 'name' => 'reference', 'required' => true),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Reference'),
|
||||
'hint' => $this->l('Votre réference interne.'),
|
||||
'name' => 'reference',
|
||||
'required' => true
|
||||
),
|
||||
),
|
||||
'submit' => array('title' => $this->l('Save'))
|
||||
);
|
||||
@ -310,6 +328,7 @@ class AdminAntadisConfiguratorController extends ModuleAdminController
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Name'),
|
||||
'hint' => $this->l('Nom de l\'option à afficher'),
|
||||
'name' => 'name',
|
||||
'required' => true,
|
||||
'lang' => true
|
||||
@ -317,13 +336,16 @@ class AdminAntadisConfiguratorController extends ModuleAdminController
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Value'),
|
||||
'hint' => $this->l('Référence ou valeur de l\'option'),
|
||||
'name' => 'value',
|
||||
'required' => true,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Price'),
|
||||
'hint' => $this->l('Prix génerique de l\'option'),
|
||||
'name' => 'price',
|
||||
'value' => 0,
|
||||
'required' => true
|
||||
),
|
||||
),
|
||||
|
@ -124,6 +124,7 @@ class AdminAntadisConfiguratorProductController extends ModuleAdminController
|
||||
|
||||
$this->_where = ' AND a.`id_product` = '.(int)$id_product.' AND a.`id_product_configurator_opt_group` = '.(int)$id_product_configurator_opt_group;
|
||||
|
||||
|
||||
self::$currentIndex = self::$currentIndex.'&id_product='.$id_product;
|
||||
$this->addRowAction('edit');
|
||||
|
||||
@ -163,13 +164,14 @@ class AdminAntadisConfiguratorProductController extends ModuleAdminController
|
||||
'price' => array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Price'),
|
||||
'hint' => $this->l('Impact de prix de l\'option'),
|
||||
'name' => 'price',
|
||||
'required' => true,
|
||||
),
|
||||
),
|
||||
'submit' => array('title' => $this->l('Save')),
|
||||
);
|
||||
|
||||
|
||||
// Override cancel
|
||||
self::$currentIndex = $this->context->link->getAdminLink('AdminAntadisConfiguratorProduct', false).
|
||||
'&id_product='.$optImpact->id_product.'&id_product_configurator_opt_group='.$optImpact->id_product_configurator_opt_group;
|
||||
|
@ -29,8 +29,10 @@ class AntadisConfiguratorDisplayProductFormController
|
||||
// => Option Group : label / name / ref
|
||||
// => Liste des Valeurs : name / value / price
|
||||
|
||||
$optGroupList = Product::getConfiguratorOptGroup($id_product);
|
||||
$optImpact = Product::getConfiguratorOptImpact($id_product);
|
||||
$optGroupList = ConfiguratorStorage::getConfiguratorOptGroup($id_product);
|
||||
$optImpact = ConfiguratorStorage::getConfiguratorOptImpact($id_product);
|
||||
|
||||
|
||||
$optImpactList = array();
|
||||
if (count($optImpact) > 0) {
|
||||
foreach ($optImpact as $o) {
|
||||
|
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2016 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2016 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class Adapter_ProductPriceCalculator
|
||||
{
|
||||
public function getProductPrice(
|
||||
$id_product,
|
||||
$usetax = true,
|
||||
$id_product_attribute = null,
|
||||
$decimals = 6,
|
||||
$divisor = null,
|
||||
$only_reduc = false,
|
||||
$usereduc = true,
|
||||
$quantity = 1,
|
||||
$force_associated_tax = false,
|
||||
$id_customer = null,
|
||||
$id_cart = null,
|
||||
$id_address = null,
|
||||
&$specific_price_output = null,
|
||||
$with_ecotax = true,
|
||||
$use_group_reduction = true,
|
||||
Context $context = null,
|
||||
$use_customer_price = true,
|
||||
$id_configurator = null
|
||||
) {
|
||||
return Product::getPriceStatic(
|
||||
$id_product,
|
||||
$usetax,
|
||||
$id_product_attribute,
|
||||
$decimals,
|
||||
$divisor,
|
||||
$only_reduc,
|
||||
$usereduc,
|
||||
$quantity,
|
||||
$force_associated_tax,
|
||||
$id_customer,
|
||||
$id_cart,
|
||||
$id_address,
|
||||
$specific_price_output,
|
||||
$with_ecotax,
|
||||
$use_group_reduction,
|
||||
$context,
|
||||
$use_customer_price,
|
||||
$id_configurator
|
||||
);
|
||||
}
|
||||
}
|
@ -384,9 +384,6 @@
|
||||
</div> <!-- end attributes -->
|
||||
{/if}
|
||||
</div> <!-- end product_attributes -->
|
||||
|
||||
{hook h='displayProductForm' mod='antadisconfigurator'}
|
||||
|
||||
<div class="box-cart-bottom">
|
||||
<div{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || (isset($restricted_country_mode) && $restricted_country_mode) || $PS_CATALOG_MODE} class="unvisible"{/if}>
|
||||
<p id="add_to_cart" class="buttons_bottom_block no-print">
|
||||
|
@ -534,7 +534,8 @@ class Cart extends CartCore
|
||||
|
||||
// refresh cache of self::_products
|
||||
$this->_products = $this->getProducts(true);
|
||||
return ($customization_quantity == $product_total_quantity && $this->deleteProduct((int)$id_product, (int)$id_product_attribute, null, (int)$id_address_delivery));
|
||||
return ($customization_quantity == $product_total_quantity
|
||||
&& $this->deleteProduct((int)$id_product, (int)$id_product_attribute, null, (int)$id_address_delivery, true, $id_configurator));
|
||||
}
|
||||
|
||||
/* Get customization quantity */
|
||||
|
@ -1,65 +1,6 @@
|
||||
<?php
|
||||
class Product extends ProductCore
|
||||
{
|
||||
/**
|
||||
* Product with configuration
|
||||
* @param int $id_product
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hasConfiguratorOpt($id_product)
|
||||
{
|
||||
$result = Db::getInstance()->getValue('
|
||||
SELECT count(*) AS nb
|
||||
FROM `'._DB_PREFIX_.'product_configurator_opt_group` pcog,
|
||||
`'._DB_PREFIX_.'configurator_opt_group` cog
|
||||
WHERE pcog.`id_product` = '.(int)$id_product.'
|
||||
AND cog.`id_configurator_opt_group` = pcog.`id_configurator_opt_group`');
|
||||
|
||||
return ( $result > 0 ? true : false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne les groupes options
|
||||
* @param int $id_product
|
||||
* @return array|false|NULL|mysqli_result|PDOStatement|resource
|
||||
*/
|
||||
public static function getConfiguratorOptGroup($id_product)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT pcog.*, col.`name`, cog.`type`
|
||||
FROM `'._DB_PREFIX_.'product_configurator_opt_group` pcog,
|
||||
`'._DB_PREFIX_.'configurator_opt_group` cog,
|
||||
`'._DB_PREFIX_.'configurator_opt_group_lang` col
|
||||
WHERE pcog.`id_product` = '.(int)$id_product.'
|
||||
AND cog.`id_configurator_opt_group` = col.`id_configurator_opt_group`
|
||||
AND pcog.`id_configurator_opt_group` = col.`id_configurator_opt_group`
|
||||
AND col.`id_lang` = '.(int)$context->language->id.'
|
||||
ORDER BY pcog.`position` ASC');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne les impacts
|
||||
* @param int $id_product
|
||||
* @return array|false|NULL|mysqli_result|PDOStatement|resource
|
||||
*/
|
||||
public static function getConfiguratorOptImpact($id_product)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT pcoi.`id_product_configurator_opt_impact`, pcoi.`id_product_configurator_opt_group`, pcoi.`id_configurator_opt`, col.`name`, pcoi.`price`, co.`position`
|
||||
FROM `'._DB_PREFIX_.'product_configurator_opt_impact` pcoi
|
||||
LEFT JOIN `'._DB_PREFIX_.'configurator_opt` co ON co.`id_configurator_opt` = pcoi.`id_configurator_opt`
|
||||
LEFT JOIN `'._DB_PREFIX_.'configurator_opt_lang` col
|
||||
ON (col.`id_configurator_opt` = pcoi.`id_configurator_opt` AND col.`id_lang` = '.(int)$context->language->id.')
|
||||
WHERE pcoi.`id_product` = '.(int)$id_product.'
|
||||
ORDER BY co.`position` ASC');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcul du prix d'impact suivant les éléments selectionnés
|
||||
*/
|
||||
@ -93,16 +34,6 @@ class Product extends ProductCore
|
||||
return $priceImpact;
|
||||
}
|
||||
|
||||
public function getConfiguratorOptSelected($id_configurator)
|
||||
{
|
||||
$sql = 'SELECT id_product_configurator_opt_group, id_product_configurator_opt_impact FROM ps_configurator_storage WHERE id_configurator = '.(int)$id_configurator;
|
||||
$optSelected = Db::getInstance()->executeS($sql);
|
||||
if (count($optSelected) > 0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Price calculation / Get product price
|
||||
*
|
||||
|
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
class OrderDetail extends OrderDetailCore
|
||||
{
|
||||
public $id_configurator;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => 'order_detail',
|
||||
'primary' => 'id_order_detail',
|
||||
'fields' => array(
|
||||
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_order_invoice' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_warehouse' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'product_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'product_attribute_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'product_name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true),
|
||||
'product_quantity' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true),
|
||||
'product_quantity_in_stock' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
'product_quantity_return' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'product_quantity_refunded' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'product_quantity_reinjected' =>array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'product_price' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
|
||||
'reduction_percent' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
'reduction_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'reduction_amount_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'reduction_amount_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'group_reduction' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
'product_quantity_discount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
'product_ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13'),
|
||||
'product_upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc'),
|
||||
'product_reference' => array('type' => self::TYPE_STRING, 'validate' => 'isReference'),
|
||||
'product_supplier_reference' => array('type' => self::TYPE_STRING, 'validate' => 'isReference'),
|
||||
'product_weight' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
'tax_name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
|
||||
'tax_rate' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
'tax_computation_method' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_tax_rules_group' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
'ecotax' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
'ecotax_tax_rate' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
'discount_quantity_applied' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
'download_hash' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
|
||||
'download_nb' => array('type' => self::TYPE_INT, 'validate' => 'isInt'),
|
||||
'download_deadline' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'),
|
||||
'unit_price_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'unit_price_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'total_price_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'total_price_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'total_shipping_price_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'total_shipping_price_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'purchase_supplier_price' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'original_product_price' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'original_wholesale_price' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||
'id_configurator' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Create an order detail liable to an id_order
|
||||
* @param object $order
|
||||
* @param object $cart
|
||||
* @param array $product
|
||||
* @param int $id_order_status
|
||||
* @param int $id_order_invoice
|
||||
* @param bool $use_taxes set to false if you don't want to use taxes
|
||||
*/
|
||||
protected function create(Order $order, Cart $cart, $product, $id_order_state, $id_order_invoice, $use_taxes = true, $id_warehouse = 0)
|
||||
{
|
||||
if ($use_taxes) {
|
||||
$this->tax_calculator = new TaxCalculator();
|
||||
}
|
||||
|
||||
$this->id = null;
|
||||
|
||||
$this->product_id = (int)$product['id_product'];
|
||||
$this->product_attribute_id = $product['id_product_attribute'] ? (int)$product['id_product_attribute'] : 0;
|
||||
$this->product_name = $product['name'].
|
||||
((isset($product['attributes']) && $product['attributes'] != null) ?
|
||||
' - '.$product['attributes'] : '');
|
||||
|
||||
$this->product_quantity = (int)$product['cart_quantity'];
|
||||
$this->product_ean13 = empty($product['ean13']) ? null : pSQL($product['ean13']);
|
||||
$this->product_upc = empty($product['upc']) ? null : pSQL($product['upc']);
|
||||
$this->product_reference = empty($product['reference']) ? null : pSQL($product['reference']);
|
||||
$this->product_supplier_reference = empty($product['supplier_reference']) ? null : pSQL($product['supplier_reference']);
|
||||
$this->product_weight = $product['id_product_attribute'] ? (float)$product['weight_attribute'] : (float)$product['weight'];
|
||||
$this->id_warehouse = $id_warehouse;
|
||||
|
||||
$product_quantity = (int)Product::getQuantity($this->product_id, $this->product_attribute_id);
|
||||
$this->product_quantity_in_stock = ($product_quantity - (int)$product['cart_quantity'] < 0) ?
|
||||
$product_quantity : (int)$product['cart_quantity'];
|
||||
|
||||
$this->setVirtualProductInformation($product);
|
||||
$this->checkProductStock($product, $id_order_state);
|
||||
|
||||
if ($use_taxes) {
|
||||
$this->setProductTax($order, $product);
|
||||
}
|
||||
$this->setShippingCost($order, $product);
|
||||
$this->setDetailProductPrice($order, $cart, $product);
|
||||
|
||||
// Set order invoice id
|
||||
$this->id_order_invoice = (int)$id_order_invoice;
|
||||
|
||||
// Set shop id
|
||||
$this->id_shop = (int)$product['id_shop'];
|
||||
|
||||
// Configurator - Get Id
|
||||
$this->id_configurator = (int)$product['id_configurator'];
|
||||
|
||||
// Add new entry to the table
|
||||
$this->save();
|
||||
|
||||
if ($use_taxes) {
|
||||
$this->saveTaxCalculator($order);
|
||||
}
|
||||
unset($this->tax_calculator);
|
||||
}
|
||||
}
|
@ -5,13 +5,6 @@ class CartController extends CartControllerCore
|
||||
|
||||
protected function parseConfigurator()
|
||||
{
|
||||
// @todo : in real time is it a good solution to get id before write items OR get from ps_cart_product and update it quickly
|
||||
$this->id_configurator = Db::getInstance()->getValue('SELECT (MAX(`id_configurator`)+1) FROM `'._DB_PREFIX_.'configurator_storage`');
|
||||
if ($this->id_configurator === null) {
|
||||
$this->id_configurator = 1;
|
||||
}
|
||||
|
||||
// Create array of option to retrieve price impact
|
||||
$detectOptGroup = 'optgroup-';
|
||||
$postValues = Tools::getAllValues();
|
||||
if (count($postValues) > 0) {
|
||||
@ -22,35 +15,40 @@ class CartController extends CartControllerCore
|
||||
if (is_array($v) && count($v) > 0) {
|
||||
foreach ($v as $vArray) {
|
||||
$price = Db::getInstance()->getValue('SELECT price FROM ps_product_configurator_opt_impact WHERE id_product_configurator_opt_impact = '.(int)$vArray);
|
||||
$sqlValues[] = '('.$this->id_configurator.', '.$this->id_product.', '.substr($p, strlen($detectOptGroup)).', '.pSQL($vArray).', '.$price.')';
|
||||
$sqlValues[] = '(@id_configurator, '.$this->id_product.', '.substr($p, strlen($detectOptGroup)).', '.pSQL($vArray).', '.$price.')';
|
||||
}
|
||||
} else {
|
||||
$price = Db::getInstance()->getValue('SELECT price FROM ps_product_configurator_opt_impact WHERE id_product_configurator_opt_impact = '.(int)$v);
|
||||
$sqlValues[] = '('.$this->id_configurator.', '.$this->id_product.', '.substr($p, strlen($detectOptGroup)).', '.pSQL($v).', '.$price.')';
|
||||
$sqlValues[] = '(@id_configurator, '.$this->id_product.', '.substr($p, strlen($detectOptGroup)).', '.pSQL($v).', '.$price.')';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($sqlValues) > 0) {
|
||||
$result = Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'configurator_storage` (`id_configurator`, `id_product`, `id_product_configurator_opt_group`, `id_product_configurator_opt_impact`, `price`)
|
||||
VALUES '.implode(',', $sqlValues)
|
||||
);
|
||||
// update cart_product
|
||||
if ($result) {
|
||||
Db::getInstance()->update('cart_product', array(
|
||||
'id_configurator' => (int)$this->id_configurator),
|
||||
'id_cart='.(int)$this->context->cart->id.
|
||||
' AND id_product='.(int)$this->id_product.
|
||||
' AND id_address_delivery='.(int)$this->id_address_delivery.
|
||||
' AND id_shop='.(int)$this->context->cart->id_shop.
|
||||
' AND id_product_attribute='.(int)$this->id_product_attribute.
|
||||
' AND quantity='.(int)$this->qty
|
||||
.' AND id_configurator = 0');
|
||||
}
|
||||
// Get max
|
||||
$cmaxSql = 'SELECT MAX(cp.id_configurator) AS maxCp, MAX(cs.id_configurator) AS maxCs
|
||||
FROM ps_configurator_storage cs, ps_cart_product cp';
|
||||
$max = Db::getInstance()->getRow($cmaxSql);
|
||||
$this->id_configurator = ($max['maxCp'] > $max['maxCs'] ? $max['maxCp'] : $max['maxCs']) + 1;
|
||||
// Assign id on cart_product
|
||||
if (Db::getInstance()->update('cart_product', array(
|
||||
'id_configurator' => (int)$this->id_configurator),
|
||||
'id_cart='.(int)$this->context->cart->id.
|
||||
' AND id_product='.(int)$this->id_product.
|
||||
' AND id_address_delivery='.(int)$this->id_address_delivery.
|
||||
' AND id_shop='.(int)$this->context->cart->id_shop.
|
||||
' AND id_product_attribute='.(int)$this->id_product_attribute.
|
||||
' AND quantity='.(int)$this->qty
|
||||
.' AND id_configurator = 0')) {
|
||||
|
||||
// Insert configurator options
|
||||
$result = Db::getInstance()->execute('SET @id_configurator = '.$this->id_configurator.';
|
||||
INSERT INTO `'._DB_PREFIX_.'configurator_storage`
|
||||
(`id_configurator`, `id_product`, `id_product_configurator_opt_group`, `id_product_configurator_opt_impact`, `price`)
|
||||
VALUES '.implode(',', $sqlValues)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,9 +120,30 @@ class CartController extends CartControllerCore
|
||||
$qty_to_check = $this->qty;
|
||||
$cart_products = $this->context->cart->getProducts();
|
||||
|
||||
$this->id_configurator = null;
|
||||
|
||||
if (is_array($cart_products)) {
|
||||
foreach ($cart_products as $cart_product) {
|
||||
if ((!isset($this->id_product_attribute) || $cart_product['id_product_attribute'] == $this->id_product_attribute) &&
|
||||
// Configurator
|
||||
if (isset($cart_product['id_configurator']) && $cart_product['id_configurator'] > 0) {
|
||||
if ((!isset($this->id_product_attribute) || $cart_product['id_product_attribute'] == $this->id_product_attribute) &&
|
||||
(isset($this->id_product) && $cart_product['id_product'] == $this->id_product)) {
|
||||
$qty_to_check = $cart_product['cart_quantity'];
|
||||
|
||||
if (Tools::getValue('op', 'up') == 'down') {
|
||||
$qty_to_check -= $this->qty;
|
||||
} else {
|
||||
$qty_to_check += $this->qty;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Define configurator
|
||||
$this->id_configurator = $cart_product['id_configurator'];
|
||||
}
|
||||
}
|
||||
// Default
|
||||
elseif ((!isset($this->id_product_attribute) || $cart_product['id_product_attribute'] == $this->id_product_attribute) &&
|
||||
(isset($this->id_product) && $cart_product['id_product'] == $this->id_product)) {
|
||||
$qty_to_check = $cart_product['cart_quantity'];
|
||||
|
||||
@ -135,10 +154,10 @@ class CartController extends CartControllerCore
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check product quantity availability
|
||||
if ($this->id_product_attribute) {
|
||||
if (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) {
|
||||
@ -181,7 +200,9 @@ class CartController extends CartControllerCore
|
||||
$available_cart_rules = CartRule::getCustomerCartRules($this->context->language->id, (isset($this->context->customer->id) ? $this->context->customer->id : 0), true, true, true, $this->context->cart, false, true);
|
||||
|
||||
// Configurator options
|
||||
$this->parseConfigurator();
|
||||
if ($this->id_configurator === null) {
|
||||
$this->parseConfigurator();
|
||||
}
|
||||
|
||||
// Send configurator id
|
||||
$update_quantity = $this->context->cart->updateQty(
|
||||
|
Loading…
Reference in New Issue
Block a user