php 产品属性属性获取产品属性加载产品属性附加产品属性\
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 产品属性属性获取产品属性加载产品属性附加产品属性\相关的知识,希望对你有一定的参考价值。
<?php echo $_product->getResource()->getAttribute('subtitle')->getFrontend()->getLabel($_product); ?>
<?php $subtitle = $_product->getsubtitle(); if(!empty($subtitle)){ echo '<p>'.$subtitle.'</p>'; } ?>
<?php echo Mage::getResourceModel('catalog/product')->getAttributeRawValue($_product->getId(), $attribute->getAttributeCode(), Mage::app()->getStore()->getStoreId()); ?>
<?php if ($_product->getvideo()):?>
<div class="video-holder"><?php echo $_helper->productAttribute($_product, nl2br($_product->getvideo()), 'video') ?></div>
<?php endif;?>
\!h ----- select
<?php if( $manufacturer = $_product->getmanufacturer() ){ echo '<p>'.$_product->getAttributeText('manufacturer').'</p>'; } ?>
\!h ----- wysiwyg
$_helper = $this->helper('catalog/output');
<?php $description = $_product->getdescription(); if(!empty($description)): ?>
<div class="short-description">
<div class="std">
<?php echo $_helper->productAttribute($_product, nl2br($_product->getDescription()), 'description') ?>
</div>
</div>
<?php endif; ?>
\!h ----- get all text attribute values get text attribute all values
$first_select = Mage::getModel('core/variable')->loadByCode('first_select')->getValue('html');
$first_select_values = array();
if( $first_select )
{
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect( $first_select );
foreach ( $collection->getColumnValues( $first_select ) as $key => $value ) {
if( !empty( $value ) ){
$first_select_values[$value] = $value;
}
}
sort($first_select_values);
}
get attribute text, dropdown
http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/
$_product->getAttributeText('test');
http://www.sharpdotinc.com/mdost/2009/04/06/magento-getting-product-attributes-values-and-labels/
1.$attributeId = Mage::getResourceModel('eav/entity_attribute')
2.->getIdByCode('catalog_product','attribute_code_here');
3.$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
4.$attributeOptions = $attribute ->getSource()->getAllOptions();
Для селекта продукта или категории
echo $children_category->getResource()->getAttribute('type_of_category')->getFrontend()->getValue($children_category);
\!h ----- multiselest
<?php
$genre = $_product->getAttributeText('genre');
$releasedate = $_product->getnews_to_date();
if(!empty($genre) || !empty($releasedate)):
?>
<dl class="item-options">
<?php if(!empty($genre)): ?>
<dt><?php echo $this->__('Genre'); ?>:</dt>
<dd>
<?php
if(is_array($genre)){
$counter = 0;
foreach($genre as $g){
++$counter;
if($counter != count($genre)){
echo $g.', ';
}else{
echo $g;
}
}
}else{
echo $genre;
}
?>
</dd>
<?php endif; ?>
</dl>
\!h ----- get attribute by code get attribute values by code
$attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product','label');
//print_r($attributeModel);
/*$storeId = Mage::app()->getStore()->getId();
echo $attributeModel->getStoreLabel( $storeId );*/
print_r( $attributeModel->getSource()->getAllOptions(false) )
\!h ----- получить значения определенного атрибута
$gender = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'gender');
$genderCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setAttributeFilter($gender->getId())->setPositionOrder('asc')->setStoreFilter(0, false);
foreach($genderCollection as $value)
{
print_r($value->getData('option_id'));
}
\!h ----- product image attribute product custom image
<?php
$_helper = $this->helper('catalog/output');
$currentproduct = Mage::registry('current_product');
if($currentproduct):
$currentproduct = Mage::getModel('catalog/product')->load($currentproduct->getId());
$isNewImage = $currentproduct->getResource()->getAttribute('productbgimage')->getFrontend()->getValue($currentproduct);
?>
<?php
if( $isNewImage != 'no_selection' && !empty($isNewImage))
{
$_newImg ='<div class="bg-page"><img id="your-id" src="'.$this->helper('catalog/image')->init($currentproduct, 'productbgimage').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" /></div>';
echo $_helper->productAttribute($currentproduct, $_newImg , 'productbgimage');
}
?>
<?php endif; ?>
<?php
$_product = Mage::getModel('catalog/product')->load($_product->getId());
$isNewImage = $_product->getResource()->getAttribute('producticon')->getFrontend()->getValue($_product);
if( $isNewImage != 'no_selection' && !empty($isNewImage))
{
$_newImg ='<img class="additional" src="'.$this->helper('catalog/image')->init($_product, 'producticon')->resize(51,51).'" width="51" height="51" alt="'.$this->getImageLabel($_product, 'producticon').'" title="'.$this->getImageLabel($_product, 'producticon').'" />';
echo $_helper->productAttribute($currentproduct, $_newImg , 'producticon');
}
?>
\!h ----- move custom options on product view separate options separate custom options
<reference name="product.info">
<block type="catalog/product_view_options" name="product.info.options" as="product_options" template="catalog/product/view/options.phtml">
<action method="addOptionRenderer"><type>text</type><block>catalog/product_view_options_type_text</block><template>catalog/product/view/options/type/text.phtml</template></action>
<action method="addOptionRenderer"><type>file</type><block>catalog/product_view_options_type_file</block><template>catalog/product/view/options/type/file.phtml</template></action>
<action method="addOptionRenderer"><type>select</type><block>catalog/product_view_options_type_select</block><template>catalog/product/view/options/type/select.phtml</template></action>
<action method="addOptionRenderer"><type>date</type><block>catalog/product_view_options_type_date</block><template>catalog/product/view/options/type/date.phtml</template></action>
</block>
</reference>
<reference name="product.info.options.wrapper">
<action method="unsetChild"><name>product_options</name></action>
</reference>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildHtml('product_options'); ?>
<?php endif; ?>
\!h ---- file attachment upload
<?php
$file = $_product->getdetaileddatasheet();
$baseUrl = Mage::getBaseUrl();
$fileurl1 = $baseUrl.'files/'.$file.'.pdf';
$filename1= substr(dirname(__FILE__), 0, strrpos(dirname(__FILE__), '/app')).'/files/'.$file.'.pdf';
if (file_exists($filename1)) {
$detail = '<li class="pdf"><a target="_blank" class="pdf" href="'.$fileurl1.'">Detailed Datasheet</a></li>';
}
?>
以上是关于php 产品属性属性获取产品属性加载产品属性附加产品属性\的主要内容,如果未能解决你的问题,请参考以下文章