Pre-select your product settings using a simple product URL.

How do I show a custom product with pre-selected options if the requested URL is for a simple product?

For instance:

Simple Product # 1 has:
Color: Red
URL: /simple-red.html

Simple product # 2 has:
Color: Green
URL: /simple-green.html

Custom Product:
URL: /config.html

If a user visits /simple-red.html, he must download a custom product with the Color pre-selected parameter : Red

If a user visits /simple-green.html, he must download a custom product with the Color pre-selected parameter : Green

+4
source share
1 answer

Successfully resolved the problem:

  • ProductController, . SO :
    Magento ProductController

    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];
        }
    }
    ...
    
  • . Vishal Sharma

(, ):

+1

Source: https://habr.com/ru/post/1540211/


All Articles