multimixer Posted February 3, 2014 Posted February 3, 2014 No sure if this has been addressed before, just got this from a client: Following case: Customer visit a store, add a item to cart, does not checkout and leave the store. After a month (or year or day) login again and find the product in cart again. Happy about that, checkout and pay. So far so good, point is that product was marked as "inactive", status was set to '0' How can this how can this happen? While function add_cart is checking the product status correctly before adding anything to the cart, the function restore_contents does not, it add just anything to the cart, just checking if the quantity in cart is less than 1 What I did as a quick solution is following 1) Create a function within includes/classes/shopping_cart.php that check the status function checkStatus() { global $customer_id; reset($this->contents); while (list($key,) = each($this->contents)) { $products_id = tep_get_prid($key); if (is_numeric($products_id)) { $check_product_query = tep_db_query("select products_status from " . TABLE_PRODUCTS . " where products_id = '" . (int)tep_db_input($products_id) . "'"); $check_product = tep_db_fetch_array($check_product_query); if (($check_product === false) || ($check_product['products_status'] != '1')) { unset($this->contents[$key]); if (tep_session_is_registered('customer_id')) { tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'"); } } } } } 2) Use this function at the end of restore_contents after $this->cleanup(); added $this->checkStatus(); EDIT: All spacing is getting lost in "code view" My community profile | Template system for osCommerce - New: Responsive | Feedback channel
De Dokta Posted February 3, 2014 Posted February 3, 2014 An easier way to achieve the same result goes like this: In includes/classes/shopping_cart.php below: // reset per-session cart contents, but not the database contents $this->reset(false); replace this: $products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'"); with: $products_query = tep_db_query("select c.products_id, c.customers_basket_quantity, p.products_id, p.products_status from " . TABLE_CUSTOMERS_BASKET . " c, " . TABLE_PRODUCTS . " p where customers_id = '" . (int)$customer_id . "' and c.products_id = p.products_id and p.products_status = 1"); That's all. Regards J.J.
multimixer Posted February 4, 2014 Author Posted February 4, 2014 This lead not to the same result: any inactive products will stay in customers cart in the database, above code remove them just from the session My community profile | Template system for osCommerce - New: Responsive | Feedback channel
De Dokta Posted February 4, 2014 Posted February 4, 2014 In the result it comes to the same thing: when the customer checks out, sold out items will not appear in the shopping cart and will be permanently deleted with the stored cart in the DB. But: If an item is only temporarily out of stock, it will appear again in the customers shopping cart when it is back in stock. With your solution, it is finally gone. Which solution is better depends on what you want or need.
Paul_w Posted February 27, 2014 Posted February 27, 2014 Thank you very much for this solution, twice today I have had customers order products that had been disabled. In the past using osC 2.2 the same problem also existed, customers should not be able to order a product that is no longer listed. It would be great to see this fix added into the core code.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.