How to fetch Product options label on Add To Cart button click?
-
29-03-2021 - |
Domanda
I am trying to get the configurable product selected options value, option titles on clicking the Add to cart button.
From the post content, I get the option_id
but : How we can fetch the and Option Titles.
For eg : (See Screenshot for reference )
I have ten text fields and two select fields : So on submit I need can get the values entered by the user but I am not able to fetch the titles of the text fields or the titles of the selected options.
Note : I have used "bss dependtent custom option" extension for creating the options. Thanks!
Soluzione
I have resolved my problem with the following code, If anybody face the same issue you can try this method:
/* SHOWING SELECTED CUSTOM OPTIONS ON AJAX CART POPUP */
$items = $this->_cart->getItems();
foreach($items as $product) {
$options = $product->getProduct()->getTypeInstance(true)->getOrderOptions($product->getProduct());
if ($options)
{
if (isset($options['options']))
{
$result = $options['options'];
}
if ($i == $len - 1) { // get only last product details
foreach($result as $key =>$value){
echo "<strong>".$resultoption = $value['label'].'</strong>';
echo "<p> ".$resultoption = $value['value'].'</p><br>';
}
}
}
else{
echo "NO OPTIONS"; // nothing here
}
$i++;
}
/* SHOWING SELECTED CUSTOM OPTIONS ON AJAX CART POPUP */ ` :
Thanks!
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange