Skip to main content

Magento 2 Custom product option edit using JS

Custom product option edit using JS

 <?php  
 $objectManager  = \Magento\Framework\App\ObjectManager::getInstance();  
 $cart      = $objectManager->get('\Magento\Checkout\Model\Cart');  
 //This doesn't work  
 $itemsCollection = $cart->getQuote()->getItemsCollection();  
 //This doesn't work too  
 $itemsVisible = $cart->getQuote()->getAllVisibleItems();  
 $items    = $cart->getQuote()->getAllItems();  
 $prosuctid  = $_product->getId();  
 foreach ($items as $item) {  
   $options  = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());  
   $optionsid = $item->getProductId();  
   if ($prosuctid == $optionsid) {  
     $customOptions = $options['options']; // error here, line 44  
     if (!empty($customOptions)) {  
       foreach ($customOptions as $option) {  
         $optionId  = $option['option_id'];  
         $optionValue = $option['option_value'];  
   waitForElement("#selection_option_<?= $optionValue ?>", function(){  
   waitForElement("#option-<?= $optionId ?>", function(){  
   var datatype = $("#option-<?= $optionId ?>").attr('data-type');  
   $('#option-<?= $optionId ?>').trigger('click');  
   $('#selection_option_<?= $optionValue ?>').trigger('click');  
   $('.select_<?= $optionId ?> .selection_controls .apply_btn').trigger('click');  
   });  
   });  
   waitForElement("#option-<?= $optionId ?>", function(){  
   var datatype = $("#option-<?= $optionId ?>").attr('data-type');  
   console.log(datatype)  
   if(datatype == "checkbox"){  
   setTimeout(function() {  
   $('#option-<?= $optionId ?>').trigger('click');  
   $('#option-<?= $optionId ?>').trigger('click');  
   console.log( $('#option-<?= $optionId ?>')[0]);  
   }, 1000);  
   }  
   });  
       }  
     }  
   }  
 }  
 ?>  

Comments

Popular posts from this blog

Magento 2 get category collection using specific controllers and category level using object manager

Magento 2 get category collection using object manager <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $category = $objectManager->get('Magento\Framework\Registry') ->registry('current_category'); //get current category $requestInterface = $objectManager->get('Magento\Framework\App\RequestInterface'); //echo $routeName = $requestInterface->getRouteName(); //echo $moduleName = $requestInterface->getModuleName(); $controllerName = $requestInterface->getControllerName(); //echo $actionName = $requestInterface->getActionName(); $parcatId = $category->getId(); // current Category ID $parcategory = $objectManager->create('Magento\Catalog\Model\Category') ->load($parcatId); $parent_category = $parcategory->getParentCategory(); $subcatId = $parent_category->getId(); $subcategory = $objectManager->create('Magento\Catalog\Model\Category...

Magento 2: How to use redirect URl in Router.php

Module name - **Aks_CustomUrlRouter** You have to create below listed files 1. Registration.php :: app/code/Aks/CustomUrlRouter/registration.php <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Aks_CustomUrlRouter', __DIR__ ); ?> 2. Module.xml :: app/code/Aks/CustomUrlRouter/etc/module.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Aks_CustomUrlRouter" setup_version="2.0.0"></module> </config> 3. di.xml :: app/code/Aks/CustomUrlRouter/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> ...

Magento 2 Get specific attribute (manufacturer) collection in phtml file with images using object manager

Magento 2 Get specific attribute (manufacturer) with images using object manager <?php $om = \Magento\Framework\App\ObjectManager::getInstance(); $categoryFactory = $om->get('\Magento\Catalog\Model\CategoryFactory'); $categoryHelper = $om->get('\Magento\Catalog\Helper\Category'); $categoryRepository = $om->get('\Magento\Catalog\Model\CategoryRepository'); $category = $categoryFactory->create()->load($catId); $categoryProducts = $category->getProductCollection() ->addAttributeToSelect('*'); foreach ($categoryProducts as $_product) { if($_product->getManufacturer()){ $brand_value = $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product); $brand_id = $_product->getManufacturer(); $curnt_cat_url = $category->getUrl(); $brandId = '?manufacturer='.$brand_id; $om = \Magento\Framework\App\ObjectManager::...