Magento 可配置产品属性

发布于 2024-10-17 08:05:37 字数 701 浏览 2 评论 0原文

嘿伙计们,我在使用 magento 时遇到了一个问题,我似乎无法找到解决方案。

我已经尝试了很多方法来获取可配置的产品属性(简单的产品)并列出它们,现在我有两种方式列出它们,但我使用的方式低于

$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']; } } }

我现在唯一的问题是我只需要拉回尺寸库存属性 - 查看法师文件以找到解决方案,但看不到任何内容 - 我需要的结果是在配置产品 php 文件中完成的,但我无法从需要列出尺寸属性的代码中访问它。

任何帮助都会很棒,谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗳卜坏 2024-10-24 08:05:37

解决方案:
您可以使用以下代码轻松获取任何其他 PHTML 文件上的所有可配置(产品)详细信息页面信息:
例如:就我而言,我正在获取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;?>      

谢谢,

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,

不羁少年 2024-10-24 08:05:37

找到了解决方案,我必须使用上面我已经编码的内容,并使用相关产品的尺寸,然后检查库存水平并将它们放入数组中,并在构建我的属性列表时检查库存 - 效果很好 - 其他人都有更好的解决方案请分享:D谢谢

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文