Magento可配置产品属性
hey guys, having an issue with magento which i just cant seem to find a solution to.
i have tried many ways of getting a configurable products attributes (simple products) and listing them, now i have them listing from 2 ways but the way im working with is below
$confAttributes = @$_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
$sizes = array();
foreach($confAttributes AS $atts){
//print '';//'<pre style="display:none;">'.print_r($atts).'</pre>';
if($atts['label'] == 'Size'){
foreach($atts['values'] AS $val){
$sizes[] = $val['store_label'];
}
}
}
my only problem with this now is i need to only pull back the size attributes which are in stock - looked through mage files to find solution but just cant see anything - the result i need is done in config product php file but i cant access it from in the code where i need to list the size attribute.
any help would be great, thanks!
嘿伙计们,有一个magento的问题,我似乎无法找到解决方案。 p> \ n
我已经尝试了很多方法来获取可配置的产品属性(简单的产品)并列出它们,现在我从2种方式列出它们,但我正在使用的方式是 p> p>
$ confAttributes = @ $ _ product-&gt; getTypeInstance(true) - &gt; getConfigurableAttributesAsArray($ _ product);
$ sizes = array();
foreach ($ confAttributes AS $ atts){
// print''; //'&lt; pre style =“display:none;”&gt;'。print_r($ atts)。'&lt; / pre&gt;';
if($ atts ['label'] =='Size'){
foreach($ atts ['values'] AS $ val){
$ sizes [] = $ val ['store_label'] ;
}
}
}
code> pre>
我现在唯一的问题是我只需要拉回尺寸属性 有货 - 通过mage文件查找解决方案,但只是看不到任何东西 - 我需要的结果是在配置产品php文件中完成但我无法从代码中访问它,我需要列出size属性。 p> \ n
任何帮助都会很棒,谢谢! p>
div>
found the solution, i had to use the above what i had already coded and use assosicated products for the size and then check the stock levels and put them into an array and check the stock when building my attribute list - works great - anyone else have a better solution please share :D thanks
Solution: You can get easily all configurable(product) details page information on any other PHTML file by using following code: e.g.: in my case i'm getting details on catalog/product/list.phtml.
<script src="<?php echo Mage::getBaseUrl('js') ?>varien/configurable.js" type="text/javascript"></script>
<?php
$temp = new Mage_Catalog_Block_Product_View_Type_Configurable();
$temp->setData('product', $_product);
$_attributes = Mage::helper('core')->decorateArray($temp->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<?php foreach($_attributes as $_attribute): ?>
<?php
$prices = $_attribute->getPrices();
foreach($prices as $price) {
echo $price['pricing_value'] . "<br/>";
}
?>
<?php endforeach; ?>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $temp->getJsonConfig() ?>);
</script>
<?php endif;?>
Thanks,