Question

enter image description here - Product is eligible for purchase and lease - purchase price is 240 - lease price is 24 per month (240 for 240 months)

1. How to make price dependent with this custom option with main price

ex.

  1. If Option is purchase then price will be 240
  2. If option will be lease the price will be Main price/Rental Term

2. How to make combination price for Rental Term and Service (Both are product custom option)

Was it helpful?

Solution

You have to purchase the dependent custom option extension Or create the custom module. Link for extension,

  1. https://shop.emiprotechnologies.com/dependent-custom-options-for-magento-2.html

  2. https://bsscommerce.com/magento-2-dependent-custom-options-extension.html

  3. https://www.mageworx.com/magento-2-advanced-product-options-suite.html (Recommended)..

If you want to create the custom functionality for set the custom price based on the selection then you must need to set the price using the observer.

I don't have checked this code works or not but you can use the logic.Please don't use object manager as well.You need to create the block file to get the product collection.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);

$values = array();
foreach ($product->getOptions() as $o) {
           $p = $o->getValues();
        }
    }
  foreach($p as $v)
        {
            $values[$v->getId()]['option_type_id']= $v->getId();
                $values[$v->getId()]['title']= 'test';
                $values[$v->getId()]['price']= 23;
                $values[$v->getId()]['price_type']= 'fixed';
                $values[$v->getId()]['sku']= $value1;

          }
        $v->setValues($values);
        $v->saveValues();
$product->save();

OTHER TIPS

Custom options are one of the inseparable parts of a product in Magento. Store owners often need to offer custom options dependent on each other. For ex., you need to show 'Green' color only when the size 'Large' is selected.

I recommend Dependant custom option Magento Extension to you. This extension facilitates admin to show or hide the custom options based on a selection of the parent custom options. Admin can quickly set the dependency relation between the custom options. Admin can select which custom option will behave as a parent and which as a child.

I hope this will help.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top