potteryhouse / stock_by_attribute_1.5.4

Stock by Attribute for Zen Cart 1.5.3
GNU General Public License v2.0
2 stars 5 forks source link

Verify functionality of cartProductCount in includes/functions/extra_functions/products_with_attributes.php #19

Open mc12345678 opened 9 years ago

mc12345678 commented 9 years ago

The function cartProductCount located in includes/functions/extra_functions/products_with_attributes.php and used in includes/modules/pages/shopping_cart/header_php.php returns the number of times the product appears in any shopping cart, not specifically the shopping cart of the current session/customers_basket_id (stored in the cart of the current session).

This information is then acted upon when displaying the shopping_cart.

Change necessary may only be to add cart session information into the query. The situation is not highly likely to be observed, though when quantities of a product or quantities of a store are limited, then if two or more individuals have added the same product to their cart at the same time (or stored the cart contents), issues may arise.

mc12345678 commented 9 years ago

Ran an experiment. the data to populate a non-zero response from cartProductCount requires that the customer be logged in (customers_basket is not populated until then) and to have added a product to the cart. As originally written, this function would return a number that corresponded to the total number of the product that was stored by all customers in their respective cart that was populated after login. This would cause the shopping_cart/header_php.php file to iterate through the customer's session cart looking for duplicates, even if the customer in question did not have any items in their own stored cart. So, by limiting the cart count function to just the current session result, the returned data is applicable to only the current user, not to all saved carts.

Possibly still some question as to the importance and functionality of this section, but for now it doesn't seem like it is causing an issue, so having fixed the count return in pull request #15, moving on to return to a review of the triple for loop code in includes/modules/pages/shopping_cart/header_php.php possibly later. Seems like there may be a more compact method to accomplish that iteration/retrieve those results, but first need to understand it.

mc12345678 commented 8 years ago

While the cartProductCount code still exists and is modified to only return the information for the currently logged in customer, the use of the code has been removed from the remainder of the SBA plugin. Would love to hear the reason/need for it, but currently functionality along the lines of the ZC default code is offered through the separate extra_cart_actions file and its interactions with other code written to evaluate how various attributes affect the option(s) being stock related or not. For example, text in a text box is not considered a stockable quantity at this point and all such text boxes are treated as if they do not affect stock. I haven't added a switch yet to modify that aspect, but if tracked by SBA then if I recall my tests correctly text in one text box of a product should not be considered a different product than if everything else is the same that the text is different in the other product. I believe that somewhere in there mixed quantity may have a part in this, but I'll update this as the testing is again completed.