Post by drest341 » Mon Feb 26, 2024 4:57 pm

Hi there
I added an extra value in product tbl "B_weight" which i need it to control the checkout process, so if this value is over , let's say 35, then display an error in checkout page.

How can i calculate if i put in cart, two different products ,
product1 has B_weight=10 , qty=2 and ....
product2 has B_weight=20 , qty=1
display total B_weight =40? - "error - is over 35"

i added the code bellow in /catalog/controller/checkout/ShippingMethod.php , but doesn't work properly.
It calculates only two of added products in cart.

-----------------------------------------------------------------------------
//check B_weight - limit to 35
$sql = $this->db->query("SELECT * FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product['product_id'] . "'");
$sql = $sql->row;
$B_weight = $sql['B_weight'];
$total_B_weight_of_order = $B_weight * $cart_total;

if ($total_B_weight_of_order >= 35) {
$json['error']['warning'] = " *** Error in order ! ";
}
------------------------------------------------------------------------------
Thnx for your time.
Any suggestion is appreciated.

Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.


User avatar
New member

Posts

Joined
Fri Feb 21, 2014 10:47 pm
Location - Athens

Post by drest341 » Mon Feb 26, 2024 5:34 pm

drest341 wrote:
Mon Feb 26, 2024 4:57 pm
Hi there
I added an extra value in product tbl "B_weight" which i need it to control the checkout process, so if this value is over , let's say 35, then display an error in checkout page.

How can i calculate if i put in cart, two different products ,
product1 has B_weight=10 , qty=2 and ....
product2 has B_weight=20 , qty=1
display total B_weight =40? - "error - is over 35"

i added the code bellow in /catalog/controller/checkout/ShippingMethod.php , but doesn't work properly.
It calculates only two of added products in cart.

-----------------------------------------------------------------------------
//check B_weight - limit to 35
$sql = $this->db->query("SELECT * FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product['product_id'] . "'");
$sql = $sql->row;
$B_weight = $sql['B_weight'];
$total_B_weight_of_order = $B_weight * $cart_total;

if ($total_B_weight_of_order >= 35) {
$json['error']['warning'] = " *** Error in order ! ";
}
------------------------------------------------------------------------------
Thnx for your time.
Any suggestion is appreciated.
Finally i did it changing the above code as bellow.
-------------------------------------------------------------------------------
$total_B_weight _of_order = 0;
foreach ($this->cart->getProducts() as $product) {
$sql = $this->db->query("SELECT * FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product['product_id'] . "'");
$sql = $sql->row;
$B_weight = $sql['B_weight'];

$total_Bweight_of_order += $product['quantity'] * $B_weight;
}

if ($total_Bweight_of_order >= 35) {
$json['error']['warning'] = " ***Error no B order can be shipped ! ";
}

Any fool can write code that a computer can understand. Good programmers write code that humans can understand ~ Martin Fowler.


User avatar
New member

Posts

Joined
Fri Feb 21, 2014 10:47 pm
Location - Athens
Who is online

Users browsing this forum: No registered users and 9 guests