问题
How to show configurable product with preselected options if requested url is for simple product?
For example:
Simple product #1 has:
Color: Red
URL: /simple-red.html
Simple product #2 has:
Color: Green
URL: /simple-green.html
Configurable product has:
URL: /config.html
If user visits /simple-red.html
it should be loaded configurable product with pre-selected option Color: Red
If user visits /simple-green.html
it should be loaded configurable product with pre-selected option Color: Green
回答1:
Successfully solved the problem:
Extended
ProductController
, to replace product id of simple product by product id of parent configurable product. Used SO Answer:
Magento Catalog ProductController rewrite
Code in customProductController
:... $productId = (int) $this->getRequest()->getParam('id'); // Get parent configurable product $_product = Mage::getModel('catalog/product')->load($productId); if ($_product->getTypeId() == "simple") { $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($_product->getId()); // If parent exists if (isset($parentIds[0])) { $productId = $parentIds[0]; } } ...
PreSelect configurable product options depending on simple product. Used link to tutorial given by Vishal Sharma
Result (sorry can't post images): Screenshot
来源:https://stackoverflow.com/questions/23607051/preselect-configurable-product-options-by-simple-product-url