Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento getAttributeName/Text_Magento_Attributes - Fatal编程技术网

Magento getAttributeName/Text

Magento getAttributeName/Text,magento,attributes,Magento,Attributes,我在玩magento产品属性的游戏 我想做的是在同一个“唯一视频号码”上附加一个“唯一产品号码”,这个号码可以完美地工作 使用以下代码的下拉属性也是如此 <script src="js/jquery-1.9.1.min.js"></script> <script src="js/avembed.js"></script> <div class="av_videoplayer" data-av-search-ean="<?php echo

我在玩magento产品属性的游戏

我想做的是在同一个“唯一视频号码”上附加一个“唯一产品号码”,这个号码可以完美地工作

使用以下代码的下拉属性也是如此

<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/avembed.js"></script>
<div class="av_videoplayer" data-av-search-ean="<?php echo $_product->getAttributeText('DropDown_Atribute') ?>"></div>


Magento提供了神奇的getter和setter,因此对于大多数产品属性,您可以使用属性名称(前面有
get
)检索它们。例如:

$freeShipping = $_product->getFreeShipping();
另一种方法是您正在使用的方法,
getAttributeText

$freeShipping = $_product->getAttributeText('free_shipping');
但是,该属性必须位于产品集合中,而大多数自定义属性都不在产品集合中。设置属性时,需要将前端产品视图页面上可见的选项
设置为Yes

否则,您可以重新创建产品集合(例如,在您自己的助手中),并按如下方式手动添加属性:

public function getMyProductCollection( $skuArray ) {
    $products = Mage::getResourceSingleton('catalog/product_collection')
        ->addAttributeToSelect(
            array(
                'free_shipping',
                'list_price',
                'manufacturer',
                'name',
                'price',
                'special_price',
                'special_from_date',
                'special_to_date',
                'thumbnail'
            )
        )
        ->addAttributeToFilter(
            'sku', array( 'in' => $skuArray )
        )
        ->load();
    return $products;
}
$_productObj = $this->helper('my_helper')->getMyProductCollection(
    $_productSkus
);
然后,您可以按如下方式使用公共功能:

public function getMyProductCollection( $skuArray ) {
    $products = Mage::getResourceSingleton('catalog/product_collection')
        ->addAttributeToSelect(
            array(
                'free_shipping',
                'list_price',
                'manufacturer',
                'name',
                'price',
                'special_price',
                'special_from_date',
                'special_to_date',
                'thumbnail'
            )
        )
        ->addAttributeToFilter(
            'sku', array( 'in' => $skuArray )
        )
        ->load();
    return $products;
}
$_productObj = $this->helper('my_helper')->getMyProductCollection(
    $_productSkus
);

请理解我所描述的原理,这段代码是不可复制的。希望对您有所帮助。

您在哪里添加了此代码???