Last active
November 13, 2020 14:13
-
-
Save jonatanrdsantos/2dfa9a1a183e16cf1a8f to your computer and use it in GitHub Desktop.
Magento get product Options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$productSku = "27609";// the SKU example | |
$productId = Mage::getModel('catalog/product')->getIdBySku( $productSku ); | |
/** @var $product Mage_Catalog_Model_Product */ | |
$product = Mage::getModel('catalog/product')->load($productId); | |
/** @var $option Mage_Catalog_Model_Product_Option */ | |
$option = $product->getOptionById('10190'); | |
foreach ($option->getValues() as $_value) { | |
/** @var $_value Mage_Catalog_Model_Product_Option_Value */ | |
var_dump($_value->getData()); | |
} | |
// via SQL | |
$query = "select o.option_id, t.title, type from catalog_product_option as o INNER JOIN catalog_product_option_type_value as v ON v.option_id = o.option_id LEFT JOIN catalog_product_option_type_title as t ON t.option_type_id = v.option_type_id where o.option_id = '10190'"; | |
// All joins | |
$queryJoins = "select prod.entity_id, prod.sku, op.option_id, opt.title, optt.title from catalog_product_entity as prod INNER JOIN catalog_product_option as op ON op.product_id = prod.entity_id LEFT JOIN catalog_product_option_title as opt ON opt.option_id = op.option_id LEFT JOIN catalog_product_option_type_value as optv ON optv.option_id = op.option_id LEFT JOIN catalog_product_option_type_title as optt ON optt.option_type_id = optv.option_type_id Where prod.has_options = 1 AND prod.entity_id = 35132"; | |
//debug alternative | |
$productID = $this->getProductId(); //Replace with your method to get your product Id. | |
$product = Mage::getModel('catalog/product')->load($productID); | |
$options = Mage::getModel('catalog/product_option')->getProductOptionCollection($product); | |
foreach ($options as $option) { | |
Mage::log('Name: ' . $option->getDefaultTitle()); | |
Mage::log(' Type: ' . $option->getType()); | |
Mage::log(' Class: ' . get_class($option)); | |
Mage::log(' Price/Type: ' . ($option->getPrice() ? $option->getPrice() : '0.00') . ' / ' . $option->getType()); | |
if ($option->getType() === 'drop_down') { | |
$values = Mage::getSingleton('catalog/product_option_value')->getValuesCollection($option); | |
Mage::log(' Values: (name/price/type)'); | |
foreach ($values as $value) { | |
Mage::log(' ' . $value->getTitle() . ' / ' . $value->getPrice() . ' / ' . $value->getPriceType());; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment