first commit
This commit is contained in:
443
modules/squaremeter/override/classes/Cart.php
Normal file
443
modules/squaremeter/override/classes/Cart.php
Normal file
@@ -0,0 +1,443 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* 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.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* 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 https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
class Cart extends CartCore
|
||||
{
|
||||
public function updateQty(
|
||||
$quantity,
|
||||
$id_product,
|
||||
$id_product_attribute = null,
|
||||
$id_customization = false,
|
||||
$operator = 'up',
|
||||
$id_address_delivery = 0,
|
||||
Shop $shop = null,
|
||||
$auto_add_cart_rule = true,
|
||||
$skipAvailabilityCheckOutOfStock = false,
|
||||
bool $preserveGiftRemoval = true,
|
||||
bool $useOrderPrices = false
|
||||
) {
|
||||
$cartProductQuantity = parent::getProductQuantity(
|
||||
$id_product,
|
||||
$id_product_attribute,
|
||||
$id_customization,
|
||||
$id_address_delivery
|
||||
);
|
||||
$index = Configuration::get('WD_CUSTOMIZATION_INDEX');
|
||||
$customization_added_to_cart = Db::getInstance()->executeS('SELECT *
|
||||
FROM `' . _DB_PREFIX_ . 'customized_data`
|
||||
WHERE `id_customization` = ' . (int) $id_customization);
|
||||
if (!$shop) {
|
||||
$shop = Context::getContext()->shop;
|
||||
}
|
||||
$dimension_data = Db::getInstance()->executeS('SELECT *
|
||||
FROM `' . _DB_PREFIX_ . 'squaremeteradmin` pa
|
||||
WHERE pa.`id_product` = ' . (int) $id_product . ' AND
|
||||
pa.`id_shop` = ' . (int) $shop->id);
|
||||
if ($dimension_data[0]['displaycalculator'] != 1) {
|
||||
parent::updateQty(
|
||||
$quantity,
|
||||
$id_product,
|
||||
$id_product_attribute,
|
||||
$id_customization,
|
||||
$operator,
|
||||
$id_address_delivery,
|
||||
$shop,
|
||||
$auto_add_cart_rule,
|
||||
$skipAvailabilityCheckOutOfStock,
|
||||
$preserveGiftRemoval,
|
||||
$useOrderPrices
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
if (Validate::isLoadedObject(Context::getContext()->customer)) {
|
||||
if ($id_address_delivery == 0 && (int) $this->id_address_delivery) {
|
||||
$id_address_delivery = $this->id_address_delivery;
|
||||
} elseif ($id_address_delivery == 0) {
|
||||
$id_address_delivery = (int) Address::getFirstCustomerAddressId(
|
||||
(int) Context::getContext()->customer->id
|
||||
);
|
||||
} elseif (!Customer::customerHasAddress(Context::getContext()->customer->id, $id_address_delivery)) {
|
||||
$id_address_delivery = 0;
|
||||
}
|
||||
} else {
|
||||
$id_address_delivery = 0;
|
||||
}
|
||||
$quantity = (int) $quantity;
|
||||
$id_product = (int) $id_product;
|
||||
$id_product_attribute = (int) $id_product_attribute;
|
||||
$product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'), $shop->id);
|
||||
if ($id_product_attribute) {
|
||||
$combination = new Combination((int) $id_product_attribute);
|
||||
if ($combination->id_product != $id_product) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!empty($id_product_attribute)) {
|
||||
$minimal_quantity = (int) Attribute::getAttributeMinimalQty($id_product_attribute);
|
||||
} else {
|
||||
$minimal_quantity = (int) $product->minimal_quantity;
|
||||
}
|
||||
if (!Validate::isLoadedObject($product)) {
|
||||
die(Tools::displayError());
|
||||
}
|
||||
if (isset(self::$_nbProducts[$this->id])) {
|
||||
unset(self::$_nbProducts[$this->id]);
|
||||
}
|
||||
if (isset(self::$_totalWeight[$this->id])) {
|
||||
unset(self::$_totalWeight[$this->id]);
|
||||
}
|
||||
$data = array(
|
||||
'cart' => $this,
|
||||
'product' => $product,
|
||||
'id_product_attribute' => $id_product_attribute,
|
||||
'id_customization' => $id_customization,
|
||||
'quantity' => $quantity,
|
||||
'operator' => $operator,
|
||||
'id_address_delivery' => $id_address_delivery,
|
||||
'shop' => $shop,
|
||||
'auto_add_cart_rule' => $auto_add_cart_rule,
|
||||
);
|
||||
Hook::exec('actionCartUpdateQuantityBefore', $data);
|
||||
if (Tools::getValue('cartsource')) {
|
||||
$suffix = '_' . Tools::getValue('id_product');
|
||||
} else {
|
||||
$suffix = '';
|
||||
}
|
||||
if ($dimension_data) {
|
||||
$qty_type = (($dimension_data[0]['displayquantity'] == 'decimalok') || ($dimension_data[0]['displayquantity'] == 'calcvisible') || ($dimension_data[0]['displayquantity'] == 'calcinvisible')) ? 'qty_type_float' : 'qty_type_integer';
|
||||
$calculation_type = $dimension_data[0]['calculationtype'];
|
||||
if ($dimension_data[0]['step'] == 0) {
|
||||
$dimension_data[0]['step'] = 0.1;
|
||||
}
|
||||
if ($calculation_type == 'weight') {
|
||||
$dimension_data[0]['step'] = 0.1;
|
||||
}
|
||||
}
|
||||
if (isset($calculation_type)) {
|
||||
// switch ($calculation_type) {
|
||||
// case "weight":
|
||||
// $minimum_customization_quantity = $dimension_data[0]['minweight'];
|
||||
// break;
|
||||
// default:
|
||||
// $minimum_customization_quantity = $dimension_data[0]['minwidth'];
|
||||
// }
|
||||
$minimum_customization_quantity = 0;
|
||||
}
|
||||
if ((int) $quantity <= 0) {
|
||||
if ((_PS_VERSION_ >= '1.7.0.0') && (_PS_VERSION_ < '1.7.7.0')) {
|
||||
return parent::deleteProduct((int) $id_product, (int) $id_product_attribute, (int) $id_customization);
|
||||
} elseif (_PS_VERSION_ >= '1.7.7.0') {
|
||||
return parent::deleteProduct((int) $id_product, (int) $id_product_attribute, (int) $id_customization, (int) $id_address_delivery, $preserveGiftRemoval);
|
||||
}
|
||||
}
|
||||
if (!$product->available_for_order
|
||||
|| (Configuration::isCatalogMode()
|
||||
&& !defined('_PS_ADMIN_DIR_'))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (empty(Tools::getValue('discretion')) && Tools::getValue('dim' . $suffix) && $id_customization) {
|
||||
$id_customization = 0;
|
||||
} elseif (Tools::getValue('discretion') && Tools::getValue('dim' . $suffix) && $id_customization) {
|
||||
$cartProductQuantity = parent::getProductQuantity(
|
||||
$id_product,
|
||||
$id_product_attribute,
|
||||
(int) $id_customization,
|
||||
(int) $id_address_delivery
|
||||
);
|
||||
if (!empty($cartProductQuantity['quantity'])) {
|
||||
$sql = 'select id_customization from ' . pSQL(_DB_PREFIX_) . 'customized_data ORDER BY id_customization DESC LIMIT 1';
|
||||
$latestcustomization = Db::getInstance()->executeS($sql);
|
||||
$id_customization = $latestcustomization[0]['id_customization'];
|
||||
$id_customization = $id_customization + 1;
|
||||
}
|
||||
}
|
||||
$cartProductQuantity = parent::getProductQuantity(
|
||||
$id_product,
|
||||
$id_product_attribute,
|
||||
(int) $id_customization,
|
||||
(int) $id_address_delivery
|
||||
);
|
||||
if (!empty($cartProductQuantity['quantity'])) {
|
||||
if (($dimension_data) && ($qty_type == 'qty_type_float')) {
|
||||
$customization_added_to_cart = Db::getInstance()->executeS('SELECT *
|
||||
FROM `' . _DB_PREFIX_ . 'customized_data`
|
||||
WHERE `id_customization` = ' . (int) $id_customization);
|
||||
if ($customization_added_to_cart) {
|
||||
$oldProductQuantity = $customization_added_to_cart[0]['converted_ea'];
|
||||
$oldTotalDimension = $customization_added_to_cart[0]['total_dimension'];
|
||||
}
|
||||
}
|
||||
$productQuantity = Product::getQuantity($id_product, $id_product_attribute, null, $this); //Available quantity
|
||||
$availableOutOfStock = Product::isAvailableWhenOutOfStock(StockAvailable::outOfStock($product->id));
|
||||
if ($operator == 'up') {
|
||||
$updateQuantity = '+ ' . $quantity; //+ 1
|
||||
if (($dimension_data) && ($qty_type == 'qty_type_float')) {
|
||||
if (($dimension_data[0]['displayquantity'] == 'calcvisible') || ($dimension_data[0]['displayquantity'] == 'calcinvisible')) {
|
||||
$newProductQuantity = $productQuantity - $quantity; //This will be the new stock available
|
||||
$newDimensionQuantity = $cartProductQuantity['quantity'] + $quantity;
|
||||
} else {
|
||||
$newProductQuantity = $productQuantity - $dimension_data[0]['step'];
|
||||
$newDimensionQuantity = $customization_added_to_cart[0]['total_dimension'] + $dimension_data[0]['step'];
|
||||
}
|
||||
} else {
|
||||
$newProductQuantity = $productQuantity - $quantity;
|
||||
}
|
||||
if ($newProductQuantity < 0 && !$availableOutOfStock && !$skipAvailabilityCheckOutOfStock) {
|
||||
return false;
|
||||
}
|
||||
} elseif ($operator == 'down') {
|
||||
$cartFirstLevelProductQuantity = parent::getProductQuantity(
|
||||
(int) $id_product,
|
||||
(int) $id_product_attribute,
|
||||
$id_customization
|
||||
);
|
||||
$updateQuantity = '- ' . $quantity;
|
||||
if ((_PS_VERSION_ >= '1.7.6.0') && (_PS_VERSION_ < '1.7.7.0')) {
|
||||
if (($dimension_data) && ($qty_type == 'qty_type_float')) {
|
||||
if (($dimension_data[0]['displayquantity'] == 'calcvisible') || ($dimension_data[0]['displayquantity'] == 'calcinvisible')) {
|
||||
$newProductQuantity = $productQuantity + $quantity;
|
||||
$newDimensionQuantity = $cartProductQuantity['quantity'] - $quantity;
|
||||
} else {
|
||||
$newProductQuantity = $customization_added_to_cart[0]['total_dimension'] + $dimension_data[0]['step'];
|
||||
$newDimensionQuantity = $customization_added_to_cart[0]['total_dimension'] - $dimension_data[0]['step'];
|
||||
}
|
||||
} else {
|
||||
$newProductQuantity = $productQuantity + $quantity;
|
||||
}
|
||||
} else {
|
||||
if ($dimension_data) {
|
||||
if (($dimension_data[0]['displayquantity'] == 'calcvisible') || ($dimension_data[0]['displayquantity'] == 'calcinvisible')) {
|
||||
$newProductQuantity = $productQuantity + $quantity;
|
||||
$newDimensionQuantity = $cartProductQuantity['quantity'] - $quantity;
|
||||
} else {
|
||||
$newProductQuantity = $customization_added_to_cart[0]['total_dimension'] + $dimension_data[0]['step'];
|
||||
$newDimensionQuantity = $customization_added_to_cart[0]['total_dimension'] - $dimension_data[0]['step'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (($dimension_data) && ($qty_type == 'qty_type_float') && (($dimension_data[0]['displayquantity'] != 'calcvisible') && ($dimension_data[0]['displayquantity'] != 'calcinvisible'))) {
|
||||
if ($newProductQuantity < $minimum_customization_quantity) {
|
||||
if ((_PS_VERSION_ >= '1.7.0.0') && (_PS_VERSION_ < '1.7.7.0')) {
|
||||
return parent::deleteProduct((int) $id_product, (int) $id_product_attribute, (int) $id_customization);
|
||||
} elseif (_PS_VERSION_ >= '1.7.7.0') {
|
||||
return parent::deleteProduct((int) $id_product, (int) $id_product_attribute, (int) $id_customization, (int) $id_address_delivery, $preserveGiftRemoval);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($cartFirstLevelProductQuantity['quantity'] <= 1
|
||||
|| $cartProductQuantity['quantity'] - $quantity <= 0) {
|
||||
if ((_PS_VERSION_ >= '1.7.0.0') && (_PS_VERSION_ < '1.7.7.0')) {
|
||||
return parent::deleteProduct((int) $id_product, (int) $id_product_attribute, (int) $id_customization);
|
||||
} elseif (_PS_VERSION_ >= '1.7.7.0') {
|
||||
return parent::deleteProduct((int) $id_product, (int) $id_product_attribute, (int) $id_customization, (int) $id_address_delivery, $preserveGiftRemoval);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (($dimension_data) && ($qty_type == 'qty_type_float')) {
|
||||
if ($dimension_data[0]['displaystartingprice'] == null) {
|
||||
$dimension_data[0]['displaystartingprice'] = 0;
|
||||
}
|
||||
if ($dimension_data[0]['displayreserve'] == null) {
|
||||
$dimension_data[0]['displayreserve'] = 0;
|
||||
}
|
||||
if ($customization_added_to_cart[0]['extra_fee'] == null) {
|
||||
$customization_added_to_cart[0]['extra_fee'] = 0;
|
||||
}
|
||||
$old_price = $customization_added_to_cart[0]['price'] - $dimension_data[0]['displaystartingprice'] - $customization_added_to_cart[0]['extra_fee'];
|
||||
$old_unit_price = round(($old_price / $oldProductQuantity), 2);
|
||||
if ($customization_added_to_cart[0]['grand_total_dimension'] != 0) {
|
||||
$conversion_rate = round(($customization_added_to_cart[0]['converted_ea'] / $customization_added_to_cart[0]['grand_total_dimension']), 2);
|
||||
$newGrandTotalDimension = round((($newDimensionQuantity * $customization_added_to_cart[0]['grand_total_dimension']) / $oldProductQuantity), 2);
|
||||
$newConvertedEa = $newDimensionQuantity;
|
||||
$newDimensionQuantity = $newGrandTotalDimension;
|
||||
} else {
|
||||
$newConvertedEa = round((($newDimensionQuantity * $oldProductQuantity) / $oldTotalDimension), 2);
|
||||
}
|
||||
$new_price = $newConvertedEa * $old_unit_price + $dimension_data[0]['displaystartingprice'] + $customization_added_to_cart[0]['extra_fee'];
|
||||
if ($dimension_data[0]['displayreserve'] > $new_price) {
|
||||
$new_price = $dimension_data[0]['displayreserve'];
|
||||
}
|
||||
if (($dimension_data[0]['displayquantity'] == 'calcvisible') || ($dimension_data[0]['displayquantity'] == 'calcinvisible')) {
|
||||
$update = '`quantity` ' . $updateQuantity;
|
||||
$new_dimension_text = '(Total ' . $newDimensionQuantity . ' ' . $dimension_data[0]['conversionunit'] . ')';
|
||||
} else {
|
||||
$new_dimension_text = '(Total ' . $newDimensionQuantity . ' ' . $dimension_data[0]['conversionunit'] . ')';
|
||||
$update = $quantity;
|
||||
}
|
||||
Db::getInstance()->execute(
|
||||
'UPDATE `' . _DB_PREFIX_ . 'customized_data`
|
||||
SET `price` = ' . (float) $new_price . ',
|
||||
`value` = "' . pSQL($new_dimension_text) . '",
|
||||
`total_dimension` = ' . (float) $newDimensionQuantity . ',
|
||||
`grand_total_dimension` = ' . (float) $newGrandTotalDimension . ',
|
||||
`converted_ea` = ' . (float) $newConvertedEa . '
|
||||
WHERE `id_customization` = ' . (int) $id_customization . '
|
||||
LIMIT 1'
|
||||
);
|
||||
Db::getInstance()->execute(
|
||||
'UPDATE `' . _DB_PREFIX_ . 'cart_product`
|
||||
SET `quantity` = ' . (int) $update . '
|
||||
WHERE `id_product` = ' . (int) $id_product .
|
||||
' AND `id_customization` = ' . (int) $id_customization .
|
||||
(!empty($id_product_attribute) ? ' AND `id_product_attribute` = ' . (int) $id_product_attribute : '') . '
|
||||
AND `id_cart` = ' . (int) $this->id . (Configuration::get('PS_ALLOW_MULTISHIPPING') && parent::isMultiAddressDelivery() ? ' AND `id_address_delivery` = ' . (int) $id_address_delivery : '') . '
|
||||
LIMIT 1'
|
||||
);
|
||||
} else {
|
||||
Db::getInstance()->execute(
|
||||
'UPDATE `' . _DB_PREFIX_ . 'cart_product`
|
||||
SET `quantity` = `quantity` ' . (int) $updateQuantity . '
|
||||
WHERE `id_product` = ' . (int) $id_product .
|
||||
' AND `id_customization` = ' . (int) $id_customization .
|
||||
(!empty($id_product_attribute) ? ' AND `id_product_attribute` = ' . (int) $id_product_attribute : '') . '
|
||||
AND `id_cart` = ' . (int) $this->id . (Configuration::get('PS_ALLOW_MULTISHIPPING') && parent::isMultiAddressDelivery() ? ' AND `id_address_delivery` = ' . (int) $id_address_delivery : '') . '
|
||||
LIMIT 1'
|
||||
);
|
||||
}
|
||||
} elseif ($operator == 'up') {
|
||||
$sql = 'SELECT stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity
|
||||
FROM ' . _DB_PREFIX_ . 'product p
|
||||
' . Product::sqlStock('p', $id_product_attribute, true, $shop) . '
|
||||
WHERE p.id_product = ' . $id_product;
|
||||
$result2 = Db::getInstance()->getRow($sql);
|
||||
if (Pack::isPack($id_product)) {
|
||||
$result2['quantity'] = Pack::getQuantity($id_product, $id_product_attribute, null, $this);
|
||||
}
|
||||
if (!Product::isAvailableWhenOutOfStock((int) $result2['out_of_stock']) && !$skipAvailabilityCheckOutOfStock) {
|
||||
if ((int) $quantity > $result2['quantity']) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((int) $quantity < $minimal_quantity) {
|
||||
return -1;
|
||||
}
|
||||
$result_add = Db::getInstance()->insert('cart_product', array(
|
||||
'id_product' => (int) $id_product,
|
||||
'id_product_attribute' => (int) $id_product_attribute,
|
||||
'id_cart' => (int) $this->id,
|
||||
'id_address_delivery' => (int) $id_address_delivery,
|
||||
'id_shop' => $shop->id,
|
||||
'quantity' => (int) $quantity,
|
||||
'date_add' => date('Y-m-d H:i:s'),
|
||||
'id_customization' => (int) $id_customization,
|
||||
));
|
||||
if (!$result_add) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$this->_products = parent::getProducts(true);
|
||||
parent::update();
|
||||
$context = Context::getContext()->cloneContext();
|
||||
$context->cart = $this;
|
||||
Cache::clean('getContextualValue_*');
|
||||
CartRule::autoRemoveFromCart();
|
||||
if ($auto_add_cart_rule) {
|
||||
CartRule::autoAddToCart($context);
|
||||
}
|
||||
if (($product->customizable) || (Tools::getValue('dim' . $suffix))) {
|
||||
$sql = 'select id_customization from ' . pSQL(_DB_PREFIX_) . 'customized_data ORDER BY id_customization DESC LIMIT 1';
|
||||
$latestcustomization = Db::getInstance()->executeS($sql);
|
||||
$id_customization = $latestcustomization[0]['id_customization'];
|
||||
return parent::_updateCustomizationQuantity(
|
||||
(int) $quantity,
|
||||
(int) $id_customization,
|
||||
(int) $id_product,
|
||||
(int) $id_product_attribute,
|
||||
(int) $id_address_delivery,
|
||||
$operator
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add customization item to database.
|
||||
*
|
||||
* @param int $id_product Product ID
|
||||
* @param int $id_product_attribute ProductAttribute ID
|
||||
* @param int $index Index
|
||||
* @param int $type Type enum
|
||||
* - Product::CUSTOMIZE_FILE
|
||||
* - Product::CUSTOMIZE_TEXTFIELD
|
||||
* @param string $field Field
|
||||
* @param int $quantity Quantity
|
||||
*
|
||||
* @return bool Success
|
||||
*/
|
||||
public function _addCustomization2($id_product, $id_product_attribute, $index, $type, $field, $quantity, $dimension_price)
|
||||
{
|
||||
$id_customization = 0;
|
||||
$exising_customization = Db::getInstance()->executeS(
|
||||
'SELECT cu.`id_customization`, cd.`index`, cd.`value`, cd.`type` FROM `' . _DB_PREFIX_ . 'customization` cu
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'customized_data` cd
|
||||
ON cu.`id_customization` = cd.`id_customization`
|
||||
WHERE cu.id_cart = ' . (int) $this->id . '
|
||||
AND cu.id_product = ' . (int) $id_product . '
|
||||
AND in_cart = 0'
|
||||
);
|
||||
if ($exising_customization) {
|
||||
foreach ($exising_customization as $customization) {
|
||||
if ($customization['type'] == $type && $customization['index'] == $index) {
|
||||
Db::getInstance()->execute('
|
||||
DELETE FROM `' . _DB_PREFIX_ . 'customized_data`
|
||||
WHERE id_customization = ' . (int) $customization['id_customization'] . '
|
||||
AND type = ' . (int) $customization['type'] . '
|
||||
AND `index` = ' . (int) $customization['index']);
|
||||
if ($type == Product::CUSTOMIZE_FILE) {
|
||||
@unlink(_PS_UPLOAD_DIR_ . $customization['value']);
|
||||
@unlink(_PS_UPLOAD_DIR_ . $customization['value'] . '_small');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$id_customization = $exising_customization[0]['id_customization'];
|
||||
} else {
|
||||
if ($this->id) {
|
||||
Db::getInstance()->execute(
|
||||
'INSERT INTO `' . _DB_PREFIX_ . 'customization` (`id_cart`, `id_product`, `id_product_attribute`, `quantity`)
|
||||
VALUES (' . (int) $this->id . ', ' . (int) $id_product . ', ' . (int) $id_product_attribute . ', ' . (int) $quantity . ')'
|
||||
);
|
||||
$id_customization = Db::getInstance()->Insert_ID();
|
||||
}
|
||||
}
|
||||
if ($id_customization) {
|
||||
$query = 'INSERT INTO `' . _DB_PREFIX_ . 'customized_data` (`id_customization`, `type`, `index`, `value`, `dimension_price`)
|
||||
VALUES (' . (int) $id_customization . ', ' . (int) $type . ', ' . (int) $index . ', \'' . pSQL($field) . '\'' . ', ' . (float) $dimension_price . ')';
|
||||
if (!Db::getInstance()->execute($query)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function addTextFieldToProductOverride($id_product, $id_product_attribute, $index, $type, $text_value, $dimension_price, $quantity = 0)
|
||||
{
|
||||
return $this->_addCustomization2($id_product, $id_product_attribute, $index, $type, $text_value, $quantity, $dimension_price);
|
||||
}
|
||||
}
|
||||
364
modules/squaremeter/override/classes/Product.php
Normal file
364
modules/squaremeter/override/classes/Product.php
Normal file
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2021 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:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* 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-2021 PrestaShop SA
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
use \Group as G;
|
||||
|
||||
class Product extends ProductCore
|
||||
{
|
||||
public static function priceCalculation(
|
||||
$id_shop,
|
||||
$id_product,
|
||||
$id_product_attribute,
|
||||
$id_country,
|
||||
$id_state,
|
||||
$zipcode,
|
||||
$id_currency,
|
||||
$id_group,
|
||||
$quantity,
|
||||
$use_tax,
|
||||
$decimals,
|
||||
$only_reduc,
|
||||
$use_reduc,
|
||||
$with_ecotax,
|
||||
&$specific_price,
|
||||
$use_group_reduction,
|
||||
$id_customer = 0,
|
||||
$use_customer_price = true,
|
||||
$id_cart = 0,
|
||||
$real_quantity = 0,
|
||||
$id_customization = 0
|
||||
) {
|
||||
static $address = null;
|
||||
static $context = null;
|
||||
|
||||
if ($context == null) {
|
||||
$context = Context::getContext()->cloneContext();
|
||||
}
|
||||
|
||||
if ($address === null) {
|
||||
if (is_object($context->cart) && $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != null) {
|
||||
$id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
|
||||
$address = new Address($id_address);
|
||||
} else {
|
||||
$address = new Address();
|
||||
}
|
||||
}
|
||||
if ($id_shop !== null && $context->shop->id != (int) $id_shop) {
|
||||
$context->shop = new Shop((int) $id_shop);
|
||||
}
|
||||
if (!$use_customer_price) {
|
||||
$id_customer = 0;
|
||||
}
|
||||
if ($id_product_attribute === null) {
|
||||
$id_product_attribute = Product::getDefaultAttribute($id_product);
|
||||
}
|
||||
$cache_id = (int) $id_product . '-' . (int) $id_shop . '-' . (int) $id_currency . '-' . (int) $id_country . '-' . $id_state . '-' . $zipcode . '-' . (int) $id_group .
|
||||
'-' . (int) $quantity . '-' . (int) $id_product_attribute . '-' . (int) $id_customization .
|
||||
'-' . (int) $with_ecotax . '-' . (int) $id_customer . '-' . (int) $use_group_reduction . '-' . (int) $id_cart . '-' . (int) $real_quantity .
|
||||
'-' . ($only_reduc ? '1' : '0') . '-' . ($use_reduc ? '1' : '0') . '-' . ($use_tax ? '1' : '0') . '-' . (int) $decimals;
|
||||
// reference parameter is filled before any returns
|
||||
$specific_price = SpecificPrice::getSpecificPrice(
|
||||
(int) $id_product,
|
||||
$id_shop,
|
||||
$id_currency,
|
||||
$id_country,
|
||||
$id_group,
|
||||
$quantity,
|
||||
$id_product_attribute,
|
||||
$id_customer,
|
||||
$id_cart,
|
||||
$real_quantity
|
||||
);
|
||||
if (isset(self::$_prices[$cache_id])) {
|
||||
return self::$_prices[$cache_id];
|
||||
}
|
||||
|
||||
// fetch price & attribute price
|
||||
$cache_id_2 = $id_product . '-' . $id_shop;
|
||||
if (!isset(self::$_pricesLevel2[$cache_id_2])) {
|
||||
$sql = new DbQuery();
|
||||
$sql->select('product_shop.`price`, product_shop.`ecotax`');
|
||||
$sql->from('product', 'p');
|
||||
$sql->innerJoin('product_shop', 'product_shop', '(product_shop.id_product=p.id_product AND product_shop.id_shop = ' . (int) $id_shop . ')');
|
||||
$sql->where('p.`id_product` = ' . (int) $id_product);
|
||||
if (Combination::isFeatureActive()) {
|
||||
$sql->select('IFNULL(product_attribute_shop.id_product_attribute,0) id_product_attribute, product_attribute_shop.`price` AS attribute_price, product_attribute_shop.default_on');
|
||||
$sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.id_product = p.id_product AND product_attribute_shop.id_shop = ' . (int) $id_shop . ')');
|
||||
} else {
|
||||
$sql->select('0 as id_product_attribute');
|
||||
}
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
if (is_array($res) && count($res)) {
|
||||
foreach ($res as $row) {
|
||||
$array_tmp = array(
|
||||
'price' => $row['price'],
|
||||
'ecotax' => $row['ecotax'],
|
||||
'attribute_price' => (isset($row['attribute_price']) ? $row['attribute_price'] : null),
|
||||
);
|
||||
self::$_pricesLevel2[$cache_id_2][(int) $row['id_product_attribute']] = $array_tmp;
|
||||
if (isset($row['default_on']) && $row['default_on'] == 1) {
|
||||
self::$_pricesLevel2[$cache_id_2][0] = $array_tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset(self::$_pricesLevel2[$cache_id_2][(int) $id_product_attribute])) {
|
||||
return;
|
||||
}
|
||||
$result = self::$_pricesLevel2[$cache_id_2][(int) $id_product_attribute];
|
||||
if (!$specific_price || $specific_price['price'] < 0) {
|
||||
$price = (float) $result['price'];
|
||||
} else {
|
||||
$price = (float) $specific_price['price'];
|
||||
}
|
||||
// convert only if the specific price is in the default currency (id_currency = 0)
|
||||
if (!$specific_price || !($specific_price['price'] >= 0 && $specific_price['id_currency'])) {
|
||||
$price = Tools::convertPrice($price, $id_currency);
|
||||
if (isset($specific_price['price']) && $specific_price['price'] >= 0) {
|
||||
$specific_price['price'] = $price;
|
||||
}
|
||||
}
|
||||
// Attribute price
|
||||
if (is_array($result) && (!$specific_price || !$specific_price['id_product_attribute'] || $specific_price['price'] < 0)) {
|
||||
$attribute_price = Tools::convertPrice($result['attribute_price'] !== null ? (float) $result['attribute_price'] : 0, $id_currency);
|
||||
// If you want the default combination, please use NULL value instead
|
||||
if ($id_product_attribute !== false) {
|
||||
$price += $attribute_price;
|
||||
}
|
||||
}
|
||||
$original_price_before_mod = $price; // We keep the original price to detect the effects with the customization price
|
||||
$sql = '
|
||||
SELECT `index`
|
||||
FROM `' . _DB_PREFIX_ . 'customized_data`
|
||||
WHERE `id_customization` = ' . (int) $id_customization;
|
||||
$check_multiple_customization = array();
|
||||
$check_multiple_customization = Db::getInstance()->executeS($sql);
|
||||
|
||||
if (sizeof($check_multiple_customization) > 1) {
|
||||
foreach ($check_multiple_customization as $index) {
|
||||
$product_customization_index = $index['index'];
|
||||
// Customization price
|
||||
if ((int) $id_customization) {
|
||||
if ($product_customization_index == Configuration::get('WD_CUSTOMIZATION_INDEX')) {
|
||||
if ($quantity == 1) {
|
||||
$price = Tools::convertPrice(Customization::getCustomizationPrice($id_customization), $id_currency);
|
||||
}
|
||||
} else {
|
||||
$price += Tools::convertPrice(Customization::getCustomizationPrice($id_customization), $id_currency);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$product_customization_index = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
// Customization price
|
||||
if ((int) $id_customization) {
|
||||
if ($product_customization_index == Configuration::get('WD_CUSTOMIZATION_INDEX')) {
|
||||
if ($quantity == 1) {
|
||||
$price = Tools::convertPrice(Customization::getCustomizationPrice($id_customization), $id_currency);
|
||||
}
|
||||
} else {
|
||||
$price += Tools::convertPrice(Customization::getCustomizationPrice($id_customization), $id_currency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tax
|
||||
$address->id_country = $id_country;
|
||||
$address->id_state = $id_state;
|
||||
$address->postcode = $zipcode;
|
||||
$tax_manager = TaxManagerFactory::getManager($address, Product::getIdTaxRulesGroupByIdProduct((int) $id_product, $context));
|
||||
$product_tax_calculator = $tax_manager->getTaxCalculator();
|
||||
|
||||
if ((int) $id_customer > 0) {
|
||||
$customer = new Customer((int) $id_customer);
|
||||
if (!Validate::isLoadedObject($customer)) {
|
||||
die(Tools::displayError());
|
||||
}
|
||||
$id_group_found = $customer->id_default_group;
|
||||
} else {
|
||||
$id_group_found = $id_group;
|
||||
}
|
||||
$sql = '
|
||||
SELECT `price_display_method`
|
||||
FROM `' . _DB_PREFIX_ . 'group`
|
||||
WHERE `id_group` = ' . (int) $id_group_found;
|
||||
$display_method = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
|
||||
if (($id_customization) && ($quantity == 1) && ($display_method == 0)) {
|
||||
if ($product_customization_index == Configuration::get('WD_CUSTOMIZATION_INDEX')) {
|
||||
$price = $product_tax_calculator->removeTaxes($price);
|
||||
}
|
||||
}
|
||||
|
||||
// Add Tax
|
||||
if ($use_tax) {
|
||||
if ($product_customization_index == Configuration::get('WD_CUSTOMIZATION_INDEX')) {
|
||||
$price = $product_tax_calculator->addTaxes($price);
|
||||
$original_price_before_mod = $product_tax_calculator->addTaxes($original_price_before_mod);
|
||||
} else {
|
||||
$price = $product_tax_calculator->addTaxes($price);
|
||||
}
|
||||
}
|
||||
// Eco Tax
|
||||
if (($result['ecotax'] || isset($result['attribute_ecotax'])) && $with_ecotax) {
|
||||
$ecotax = $result['ecotax'];
|
||||
if (isset($result['attribute_ecotax']) && $result['attribute_ecotax'] > 0) {
|
||||
$ecotax = $result['attribute_ecotax'];
|
||||
}
|
||||
if ($id_currency) {
|
||||
$ecotax = Tools::convertPrice($ecotax, $id_currency);
|
||||
}
|
||||
if ($use_tax) {
|
||||
static $psEcotaxTaxRulesGroupId = null;
|
||||
if ($psEcotaxTaxRulesGroupId === null) {
|
||||
$psEcotaxTaxRulesGroupId = (int) Configuration::get('PS_ECOTAX_TAX_RULES_GROUP_ID');
|
||||
}
|
||||
// reinit the tax manager for ecotax handling
|
||||
$tax_manager = TaxManagerFactory::getManager(
|
||||
$address,
|
||||
$psEcotaxTaxRulesGroupId
|
||||
);
|
||||
$ecotax_tax_calculator = $tax_manager->getTaxCalculator();
|
||||
$price += $ecotax_tax_calculator->addTaxes($ecotax);
|
||||
if ($product_customization_index == Configuration::get('WD_CUSTOMIZATION_INDEX')) {
|
||||
$original_price_before_mod += $ecotax_tax_calculator->addTaxes($ecotax);
|
||||
}
|
||||
} else {
|
||||
if ($product_customization_index == Configuration::get('WD_CUSTOMIZATION_INDEX')) {
|
||||
$original_price_before_mod += $ecotax;
|
||||
}
|
||||
$price += $ecotax;
|
||||
}
|
||||
}
|
||||
// Reduction
|
||||
$specific_price_reduction = 0;
|
||||
if (($only_reduc || $use_reduc) && $specific_price) {
|
||||
if ($specific_price['reduction_type'] == 'amount') {
|
||||
$reduction_amount = $specific_price['reduction'];
|
||||
if (!$specific_price['id_currency']) {
|
||||
$reduction_amount = Tools::convertPrice($reduction_amount, $id_currency);
|
||||
}
|
||||
$specific_price_reduction = $reduction_amount;
|
||||
// Adjust taxes if required
|
||||
if (!$use_tax && $specific_price['reduction_tax']) {
|
||||
$specific_price_reduction = $product_tax_calculator->removeTaxes($specific_price_reduction);
|
||||
}
|
||||
if ($use_tax && !$specific_price['reduction_tax']) {
|
||||
$specific_price_reduction = $product_tax_calculator->addTaxes($specific_price_reduction);
|
||||
}
|
||||
} else {
|
||||
if ($product_customization_index == Configuration::get('WD_CUSTOMIZATION_INDEX')) {
|
||||
if ($original_price_before_mod == $price) {
|
||||
$specific_price_reduction = $price * $specific_price['reduction'];
|
||||
}
|
||||
} else {
|
||||
$specific_price_reduction = $price * $specific_price['reduction'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($use_reduc) {
|
||||
if ($product_customization_index == Configuration::get('WD_CUSTOMIZATION_INDEX')) {
|
||||
if ($original_price_before_mod == $price) {
|
||||
$price -= $specific_price_reduction;
|
||||
$original_price_before_mod = $price;
|
||||
}
|
||||
} else {
|
||||
$price -= $specific_price_reduction;
|
||||
}
|
||||
}
|
||||
|
||||
if ((int) $id_customization) {
|
||||
if ($product_customization_index == Configuration::get('WD_CUSTOMIZATION_INDEX')) {
|
||||
if ($quantity == 1) {
|
||||
if (!$use_reduc) {
|
||||
$specific_price_reduction = 0;
|
||||
if (($only_reduc || $use_reduc) && $specific_price) {
|
||||
if ($specific_price['reduction_type'] == 'amount') {
|
||||
$reduction_amount = $specific_price['reduction'];
|
||||
|
||||
if (!$specific_price['id_currency']) {
|
||||
$reduction_amount = Tools::convertPrice($reduction_amount, $id_currency);
|
||||
}
|
||||
|
||||
$specific_price_reduction = $reduction_amount;
|
||||
|
||||
// Adjust taxes if required
|
||||
|
||||
if (!$use_tax && $specific_price['reduction_tax']) {
|
||||
$specific_price_reduction = $product_tax_calculator->removeTaxes($specific_price_reduction);
|
||||
}
|
||||
if ($use_tax && !$specific_price['reduction_tax']) {
|
||||
$specific_price_reduction = $product_tax_calculator->addTaxes($specific_price_reduction);
|
||||
}
|
||||
} else {
|
||||
$specific_price_reduction = $price * $specific_price['reduction'];
|
||||
}
|
||||
|
||||
$price += $specific_price_reduction;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Group reduction
|
||||
if ($use_group_reduction) {
|
||||
$reduction_from_category = GroupReduction::getValueForProduct($id_product, $id_group);
|
||||
if ($reduction_from_category !== false) {
|
||||
$group_reduction = $price * (float) $reduction_from_category;
|
||||
} else { // apply group reduction if there is no group reduction for this category
|
||||
$group_reduction = (($reduc = Group::getReductionByIdGroup($id_group)) != 0) ? ($price * $reduc / 100) : 0;
|
||||
}
|
||||
if ($product_customization_index == Configuration::get('WD_CUSTOMIZATION_INDEX')) {
|
||||
if ($original_price_before_mod == $price) {
|
||||
$price -= $group_reduction;
|
||||
$original_price_before_mod = $price;
|
||||
}
|
||||
} else {
|
||||
$price -= $group_reduction;
|
||||
}
|
||||
}
|
||||
if ($only_reduc) {
|
||||
return Tools::ps_round($specific_price_reduction, $decimals);
|
||||
}
|
||||
$price = Tools::ps_round($price, $decimals);
|
||||
if ($price < 0) {
|
||||
$price = 0;
|
||||
}
|
||||
|
||||
self::$_prices[$cache_id] = $price;
|
||||
return self::$_prices[$cache_id];
|
||||
}
|
||||
|
||||
public static function addProductCustomizationPrice(&$product, &$customized_datas)
|
||||
{
|
||||
/* To fix the order confirmation page zero total problem for customized products */
|
||||
parent::addProductCustomizationPrice($product, $customized_datas);
|
||||
if ($product['total'] == 0) {
|
||||
$product['total'] = $product['total_price_tax_excl'];
|
||||
$product['total_wt'] = $product['total_price_tax_incl'];
|
||||
}
|
||||
}
|
||||
}
|
||||
29
modules/squaremeter/override/classes/index.php
Normal file
29
modules/squaremeter/override/classes/index.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2021 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This module is not a free module and all rights are reserved. It is prohibited to sell or redistribute this module for any purpose. Each license can be used only in one website. For multishop environment, a new license is required for each e-shop managed.
|
||||
*
|
||||
* 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 MEG Venture <info@megventure.com>
|
||||
* @copyright 2007-2021 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
Reference in New Issue
Block a user