you can get url
<a href="<?php echo Mage::getUrl('review/product/list', array(
'id' => $productid,
'category' => $categoryid
));?>#review-form"><?php echo $this->__('Be the first to review this product') ?></a>
To get the configurable attribute and their options value for specific product you can use the following code.
// In construct or fist loaded method
// Magento\ConfigurableProduct\Helper\Data $helper;
// $this->helper = $helper;
$options = $this->helper->getOptions($product, $this->getAllowProducts());
$attributes = [];
foreach ($product->getTypeInstance()->getConfigurableAttributes($product) as $attribute) {
$attributeOptionsData = $this->getAttributeOptionsData($attribute, $options);
if ($attributeOptionsData) {
$productAttribute = $attribute->getProductAttribute();
$attributeId = $productAttribute->getId();
$attributes[$attributeId] = [
'id' => $attributeId,
'code' => $productAttribute->getAttributeCode(),
'label' => $productAttribute->getStoreLabel($product->getStoreId()),
'options' => $attributeOptionsData,
];
}
}
print_r($attributes); exit(); // Here you will get the all array to do it in html.
For get the products options method is called in above code
public function getAllowProducts()
{
$skipSaleableCheck = $this->catalogProduct->getSkipSaleableCheck();
$products = $skipSaleableCheck ?
$this->getProduct->getTypeInstance()->getUsedProducts($this->getProduct, null) :
$this->getProduct->getTypeInstance()->getSalableUsedProducts($this->getProduct, null);
return $products;
}
And for last where you will get its options method called above
protected function getAttributeOptionsData($attribute, $config)
{
$attributeOptionsData = [];
foreach ($attribute->getOptions() as $attributeOption) {
$optionId = $attributeOption['value_index'];
$attributeOptionsData[] = [
'id' => $optionId,
'label' => $attributeOption['label'],
'products' => isset($config[$attribute->getAttributeId()][$optionId])
? $config[$attribute->getAttributeId()][$optionId]
: [],
];
}
return $attributeOptionsData;
}
Best Answer
use following code
instead of
for the configurable products.