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
Post a Comment