lat9 / edit_orders

Edit Orders: Updates for continued operation on Zen Cart v1.5.8 and later
GNU General Public License v2.0
5 stars 9 forks source link

edit_orders changes products_prid in table orders_products_attributes_stock #239

Open daphilli224 opened 2 months ago

daphilli224 commented 2 months ago

The products_prid of a product with attributes in an order is changed in table orders_products_attributes_stock when the quantity of the product is changed in edit_orders. The product must be tracked by Products With Attributes Stock (SBA) plugin. Procedure to see problem:

  1. Order a product with a single attribute (1 option, multiple option values), selecting a single option value, and check out. Note: I did not test cases when the product has multiple options.
  2. Examine products_prid in tables orders_products, orders_products_attributes, and orders_products_attributes_stock for the order and verify all are identical
  3. Edit the order to change the quantity of the product and exit edit_orders after clicking update
  4. Examine the tables again for the order. Note that products_prid in orders_products_attributes_stock is now different from that in the other tables.

At least one effect from the change in products_prid is that if the order is now deleted with the restock option chosen, the products quantity in stock in table products_with_attributes_stock is incorrect. There may be other effects that I have not noticed.

I have traced the issue to a call to zen_get_uprid around line 736 in admin/includes/classes/observers/class.products_with_attributes_stock.php where $new_attrs[$key] is structured differently than other calls to zen_get_uprid. The code segment is: foreach ($order_product_attribute_id as $key=>$opai) { $sql_data_array = array('orders_products_attributes_id' =>$opai, 'orders_id' =>$order_id, 'orders_products_id' =>$orders_products_id, 'stock_id' => $_stock_info['stock_id'], 'stock_attribute' => $_stock_info['stock_attribute'], 'customid' => $product['customid'], 'products_prid' =>zen_get_uprid($product['id'], $new_attrs[$key])); zen_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES_STOCK, $sql_data_array); //inserts data into the TABLE_ORDERS_PRODUCTS_ATTRIBUTES_STOCK table. } I found the structure of the second argument to zen_get_uprid, $new_attrs[$key], after edit_orders was array('option_id'=>'3', 'value_id'=>'255') where '3' is the option_id for the test product, and '255' is the option_value_id. Normally and before edit_orders, the second argument to zen_get_uprid is array(3=>255) for my test case. I fixed the problem by changing $new_attrs[$key] to the normal structure.

Disclaimer: I did not trace back further to see where edit_orders set or passed the data that gets into $new_attrs[$key] and whether the problem is really an edit_orders problem or an SBA problem. My apologies if this should be reported to SBA.

Dave zc158a, edit_orders 4.7.1, SBA downloaded from GitHub on 11/15/2023. Same problem exists in zc157c, edit_orders 4.6.2.

lat9 commented 2 months ago

Versions of EO prior to 4.7.0 did drop the products 'prid' from the orders-products table (see #216). I'm afraid I can't be of help with the SBA integration (or lack thereof). None of my clients use that product-variant handler.