Latest News: (loading..)
Issue Information
-
#000452
-
0 - None Assigned
-
New
-
3.0.2
-
-
Issue Confirmations
-
Yes (1)No (0)
I found a bug in the update link in the cart page
Steps to reproduce the bug
1. Open a new tab in your browser
2. open the home page oscommerce-3.0.2/oscommerce/index.php
3. sign in
4. click in any random item
5. add it to the cart
6. open a second tab in your browser
7. go to the cart page (oscommerce/index.php?Cart)
8. click in the checkout button in the second tab
9. click confirm order in the second tab
10. go back to the first tab
11. change the number of items to positive number
12. click update
It added the number to null items
It should go to “Your Shopping Cart is empty!” page
I fix this problem by checking if there exists an item in the cart before updating it.
osCommerce\OM\Core\Site\Shop\ ShoppingCart.php
in the function “public function update($item_id, $quantity)” in line 435
I added if statement to check if the item in the cart or no before adding it
In line 442 before “$this->_contents[$item_id]['quantity'] = $quantity;” I added
if(isset( $this->_contents[$item_id]['quantity'])){
the if statement end before “$this->_cleanUp();”
so the function look like the following after making the changes
Steps to reproduce the bug
1. Open a new tab in your browser
2. open the home page oscommerce-3.0.2/oscommerce/index.php
3. sign in
4. click in any random item
5. add it to the cart
6. open a second tab in your browser
7. go to the cart page (oscommerce/index.php?Cart)
8. click in the checkout button in the second tab
9. click confirm order in the second tab
10. go back to the first tab
11. change the number of items to positive number
12. click update
It added the number to null items
It should go to “Your Shopping Cart is empty!” page
I fix this problem by checking if there exists an item in the cart before updating it.
osCommerce\OM\Core\Site\Shop\ ShoppingCart.php
in the function “public function update($item_id, $quantity)” in line 435
I added if statement to check if the item in the cart or no before adding it
In line 442 before “$this->_contents[$item_id]['quantity'] = $quantity;” I added
if(isset( $this->_contents[$item_id]['quantity'])){
the if statement end before “$this->_cleanUp();”
so the function look like the following after making the changes
public function update($item_id, $quantity) {
$OSCOM_Customer = Registry::get('Customer');
$OSCOM_PDO = Registry::get('PDO');
if ( !is_numeric($quantity) ) {
$quantity = $this->getQuantity($item_id) + 1;
}
if(isset( $this->_contents[$item_id]['quantity'])){
$this->_contents[$item_id]['quantity'] = $quantity;
if ( $OSCOM_Customer->isLoggedOn() ) {
$Qupdate = $OSCOM_PDO->prepare('update :table_shopping_carts set quantity = :quantity where customers_id = :customers_id and item_id = :item_id');
$Qupdate->bindInt(':quantity', $quantity);
$Qupdate->bindInt(':customers_id', $OSCOM_Customer->getID());
$Qupdate->bindInt(':item_id', $item_id);
$Qupdate->execute();
}
}
$this->_cleanUp();
$this->_calculate();
}










