Originally Posted by
mc12345678
Couple of ways come to mind on "how" to do it. If the original item is the "first" selected (meaning it is your "template" item that had to be added before all else), then could set a session variable to the hashed products_id so that could easily pull it out of the list of product in the cart and then can make the changes necessary to the product and replace that item in the list of cart items.
I say replace because the items are added in order and remain in that order even when stored to the user's saved cart. Otherwise, depending on how many of said item is allowed in the cart, could just reference back to the integer cast products_id looking through the cart for that item regardless of the existing attributes.
Could also perhaps incorporate a separate flag (attribute?) with that product when first storing it and then as going through the cart product and identify the presence of that attribute to remove it and update the attributes.
Note that there is also likely to be an issue and need to work around the "saved cart", which also depends on the allowance of a customer to login before checking out with a fully defined cart. If a customer has logged in, has added this "default" product that isn't really ready to purchase until it has been edited, then have to do some level of control on the cart being stored/retrieved. When it is retrieved as part of logging in, the old content is placed ahead of the existing content (generally speaking) so working the "first" position in the above option may produce erroneous results. Also, comes the question of allowance/possibility to have two of the "base" product.
The other thing of note, depends on your "test" that the first product has been added. If it for some reason depends on the complete "hashed" products_id and not just the integer of it, then that somewhat throws a monkey wrench (spanner) into the works.
That hashed value is actually useful in determining which attribute(s) if any have been added to the product in that all available attribute(s) can be cycled through to recreate that value (more difficult if a text field is included) to identify which attribute(s) were originally selected. This is why I recommended earlier to replace the product in the cart rather than just add/edit attributes. Also why I brought up the cart save portion of the login, logout, time-out after login issue.
Whatever is chosen/done, ideally the solution would maintain compatibility with other expected behavior/operations to minimize any rework if other plugins were added.
As to the format of the attributes, storage/retrieval is a little different once added to the cart/order. Recommend possibly using superglobals to maybe help with development if not already in use.
Bookmarks