Preselect configurable product options by simple product URL

给你一囗甜甜゛ 提交于 2019-12-06 04:34:41

问题


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:

  1. 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 custom ProductController:

    ...
    $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];
        }
    }
    ...
    
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!