mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-03 19:53:19 +03:00
add tax rules in sync, bug fixes (#9)
* correct transfer discount * correct delete items and discount * add tax rules in sync, bug fixes
This commit is contained in:
parent
1ca1f31abc
commit
2c4f8524a6
@ -402,12 +402,12 @@ if ($history->isSuccessful() && count($history->history) > 0) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
unset($order['items'][$key]);
|
unset($order['items'][$key]);
|
||||||
$ItemDiscount = true
|
$ItemDiscount = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check items quantity
|
* Check items quantity and discount
|
||||||
*/
|
*/
|
||||||
foreach ($orderToUpdate->getProductsDetail() as $orderItem) {
|
foreach ($orderToUpdate->getProductsDetail() as $orderItem) {
|
||||||
foreach ($order['items'] as $key => $item) {
|
foreach ($order['items'] as $key => $item) {
|
||||||
@ -422,6 +422,35 @@ if ($history->isSuccessful() && count($history->history) > 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($product_id == $orderItem['product_id'] && $product_attribute_id == $orderItem['product_attribute_id']) {
|
if ($product_id == $orderItem['product_id'] && $product_attribute_id == $orderItem['product_attribute_id']) {
|
||||||
|
|
||||||
|
// discount
|
||||||
|
if (isset($item['discount']) || isset($item['discountPercent'])) {
|
||||||
|
$product = new Product((int) $product_id, false, $default_lang);
|
||||||
|
$tax = new TaxCore($product->id_tax_rules_group);
|
||||||
|
|
||||||
|
if($product_attribute_id != 0) {
|
||||||
|
$prodPrice = Combination::getPrice($product_attribute_id);
|
||||||
|
$prodPrice = $prodPrice > 0 ? $prodPrice : $product->price;
|
||||||
|
} else {
|
||||||
|
$prodPrice = $product->price;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prodPrice = $prodPrice + $prodPrice / 100 * $tax->rate;
|
||||||
|
|
||||||
|
$productPrice = $prodPrice - $item['discount'];
|
||||||
|
$productPrice = $productPrice - ($prodPrice / 100 * $item['discountPercent']);
|
||||||
|
$ItemDiscount = true;
|
||||||
|
|
||||||
|
$productPrice = round($productPrice , 2);
|
||||||
|
|
||||||
|
Db::getInstance()->execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'order_detail`
|
||||||
|
SET `unit_price_tax_incl` = '.$productPrice.'
|
||||||
|
WHERE `id_order_detail` = '.$orderItem['id_order_detail']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// quantity
|
||||||
if (isset($item['quantity']) && $item['quantity'] != $orderItem['product_quantity']) {
|
if (isset($item['quantity']) && $item['quantity'] != $orderItem['product_quantity']) {
|
||||||
Db::getInstance()->execute('
|
Db::getInstance()->execute('
|
||||||
UPDATE `'._DB_PREFIX_.'order_detail`
|
UPDATE `'._DB_PREFIX_.'order_detail`
|
||||||
@ -462,6 +491,7 @@ if ($history->isSuccessful() && count($history->history) > 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$product = new Product((int) $product_id, false, $default_lang);
|
$product = new Product((int) $product_id, false, $default_lang);
|
||||||
|
$tax = new TaxCore($product->id_tax_rules_group);
|
||||||
|
|
||||||
if($product_attribute_id != 0) {
|
if($product_attribute_id != 0) {
|
||||||
$productName = htmlspecialchars(strip_tags(Product::getProductName($product_id, $product_attribute_id)));
|
$productName = htmlspecialchars(strip_tags(Product::getProductName($product_id, $product_attribute_id)));
|
||||||
@ -473,6 +503,13 @@ if ($history->isSuccessful() && count($history->history) > 0) {
|
|||||||
$productPrice = $product->price;
|
$productPrice = $product->price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// discount
|
||||||
|
if ($newItem['discount'] || $newItem['discountPercent']) {
|
||||||
|
$productPrice = $productPrice - $newItem['discount'];
|
||||||
|
$productPrice = $productPrice - ($prodPrice / 100 * $newItem['discountPercent']);
|
||||||
|
$ItemDiscount = true;
|
||||||
|
}
|
||||||
|
|
||||||
$query .= '('
|
$query .= '('
|
||||||
.(int) $orderToUpdate->id.',
|
.(int) $orderToUpdate->id.',
|
||||||
0,
|
0,
|
||||||
@ -485,9 +522,9 @@ if ($history->isSuccessful() && count($history->history) > 0) {
|
|||||||
'.$productPrice.',
|
'.$productPrice.',
|
||||||
'.implode('', array('\'', $product->reference, '\'')).',
|
'.implode('', array('\'', $product->reference, '\'')).',
|
||||||
'.$productPrice * $newItem['quantity'].',
|
'.$productPrice * $newItem['quantity'].',
|
||||||
'.($productPrice + $productPrice / 100 * 18) * $newItem['quantity'].',
|
'.($productPrice + $productPrice / 100 * $tax->rate) * $newItem['quantity'].',
|
||||||
'.$productPrice.',
|
'.$productPrice.',
|
||||||
'.($productPrice + $productPrice / 100 * 18).',
|
'.($productPrice + $productPrice / 100 * $tax->rate).',
|
||||||
'.$productPrice.'
|
'.$productPrice.'
|
||||||
),';
|
),';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user