How can I dynamically update the sku of a product on the product page when users select its custom options? Also, how could it then be passed into the cart page?
Example: A product with sku XXX has two custom options Y and Z, which have the options of Y1, Y2 and Z1, Z2. If a user selects Y1 and Z2, I'd like to change the sku on the page to XXX-Y1-Z2 and pass that sku to the cart.
Thanks.
Best Answer
If you add a custom options to a product you can add, for example for dropdown options, a product sku suffix as shown below.
On choosing an option when adding the product to cart and retrieving the SKU in the cart
var_dump($_item->getSku());
you can see the products SKU has been changedNow for dynamically updating the SKU on the product page. For this we will need to retrieve the option values SKU's which can be done in the file
app/design/frontend/[package]/[template]/template/catalog/product/view/options.phtml
for example. In this case around line 190 after the javascript we add/replace some code as shown below. This will give you a javascript array which you can use when a custom option is selected to map the option ID to the SKU suffix and changing the displayed product SKU on the product page.