0
如何獲得magento中的活動屬性活動選項? 如何僅顯示分層導航左側塊等屬性和屬性選項。它僅顯示按所選類別顯示的活動屬性和選項。如何獲得magento中的活動屬性活動選項?
我的代碼是toolbar.phtml
<?php
if(Mage::getStoreConfig('customtoolbar/customtoolbar_general/enabled') == 1):
?>
<div class="filter-by" style="float: left; padding-left: 10px;">
<?php
$entity_type_id =Mage::getModel('catalog/product')->getResource()->getTypeId();
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')->setEntityTypeFilter($entity_type_id)->addFieldToFilter("backend_type",array("eq"=>'int'))->addFieldToFilter("frontend_input",array("eq"=>'select'))->addFieldToFilter("used_for_filter_by",array("eq"=>'1'));
?>
<table><tr><td>
<label><?php echo $this->__('Shop By') ?></label></td>
<td>
<select onchange="fillattvalue(this.value)" id="attributes" style="width: 82px;">
<option value="select"><?php echo $this->__('Please Select') ?></option>
<?php foreach($attributes as $attribute): ?>
<option value="<?php echo $attribute->getAttributeCode(); ?>">
<?php echo $attribute->getFrontendLabel() ?>
</option>
<?php endforeach; ?>
</select></td>
<td id="attvalue" style="display: none; padding-left: 10px; "></td>
</tr></table>
</div>
<?php endif ?>
<script language ="javascript" type="text/javascript">
function fillattvalue(item)
{
var parameters = {att_code : item }
var url = '<?php echo Mage::helper('adminhtml')->getUrl('customtoolbar/index/fillattvalues'); ?>';
var e = document.getElementById("attributes");
var select_index = e.options[e.selectedIndex].value;
if(select_index == "select")
{
document.getElementById('attvalue').style.display='none';
}
else
{
document.getElementById('loading-mask').style.display = 'none';
new Ajax.Request(url, {
method: 'post',
//asynchronous: false,
onSuccess: function(transport) {
document.getElementById('loading-mask').style.display='none';
if(transport.responseText) {
var response = transport.responseText;
response = response.evalJSON();
var total_length = response.length;
var html='';
var cur_url = location.href;
var cur_att = document.getElementById("attributes").value;
var cur_cat_url ='<?php echo Mage::getBaseUrl().Mage::getModel('catalog/layer')->getCurrentCategory()->getUrlPath() ?>'
html+= '<select onchange="setLocation(this.value)" style="width:82px">';
html+= '<option value="">Please Select</option>';
for (var i=1;i<total_length;i++){
var inner_parameters = {
lable : response[i]['lable'],
value : response[i]['value']
}
<?php $is_anchor = Mage::getModel('catalog/layer')->getCurrentCategory()->getIsAnchor();
if($is_anchor == 1){ ?>
var baseURL = cur_cat_url + "?" + cur_att +"=" + response[i]['value'];
<?php } else { ?>
//var baseURL = cur_url.substring(0, cur_url.indexOf('/', 14))+ "/index.php/catalogsearch/result/?q=" + response[i]['lable'];
var baseURL = '<?php echo Mage::getBaseUrl() ?>' + "catalogsearch/advanced/result/?"+item+"[]=" + response[i]['value'];
<?php } ?>
html+= '<option value="'+baseURL+'">';
html+= response[i]['lable'];
html+='</option>';
}
html+='</select>'
document.getElementById('attvalue').innerHTML=html;
document.getElementById('loading-mask').style.display='none';
document.getElementById('attvalue').style.display='inline-block';
}
},
parameters:parameters
});
}
}
</script>
indexcontroller.php代碼
<?php
class Biztech_Customtoolbar_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
public function fillattvaluesAction()
{
$att_code = $this->getRequest()->getParam('att_code');
$json = array();
$att = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $att_code);
$options = $att->getSource()->getAllOptions();
foreach($options as $option)
{
$json[] = array(
'lable' => $option['label'],
'value' => $option['value']
);
}
$this->getResponse()->setBody(Zend_Json::encode($json));
}
}
我目前使用這個擴展http://www.magentocommerce.com/ magento-connect/custom-product-grid-filters.html我這兩個文件來自這個擴展。 – Sarps