首頁>Magento>source

我已在註册過程中為客戶添加了自定義屬性供客戶選擇.為簡單起见,我们可以說這是他们最類似的颜色(color_customer).值从下拉列表中提取.前端和後端的一切都很好.我通過覆盖網格檔案將此自定義屬性添加到客戶網格中.然後我尝試在_prepareColumns函式之前获取color屬性的值.我不太確定這是正確的方法,我希望有人可以對這件事情有所了解。

   <?php
    class Company_Module_Block_Adminhtml_Customer_Grid extends      Mage_Adminhtml_Block_Customer_Grid{
    protected function _prepareCollection(){
    $collection = Mage::getResourceModel('customer/customer_collection')
        ->addNameToSelect()
        ->addAttributeToSelect('email')
        ->addAttributeToSelect('created_at')
        ->addAttributeToSelect('group_id')
        ->addAttributeToSelect('color_customer')
        ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
        ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
        ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
        ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
        ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
    $this->setCollection($collection);
    if ($this->getCollection()) {
        $this->_preparePage();
        $columnId = $this->getParam($this->getVarNameSort(), $this->_defaultSort);
        $dir      = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
        $filter   = $this->getParam($this->getVarNameFilter(), null);
        if (is_null($filter)) {
            $filter = $this->_defaultFilter;
        }
        if (is_string($filter)) {
            $data = $this->helper('adminhtml')->prepareFilterString($filter);
            $this->_setFilterValues($data);
        }
        else if ($filter && is_array($filter)) {
            $this->_setFilterValues($filter);
        }
        else if(0 !== sizeof($this->_defaultFilter)) {
            $this->_setFilterValues($this->_defaultFilter);
        }
        if (isset($this->_columns[$columnId]) && $this->_columns[$columnId]->getIndex()) {
            $dir = (strtolower($dir)=='desc') ? 'desc' : 'asc';
            $this->_columns[$columnId]->setDir($dir);
            $this->_setCollectionOrder($this->_columns[$columnId]);
        }
        if (!$this->_isExport) {
            $this->getCollection()->load();
            $this->_afterLoadCollection();
        }
    }
    return $this;
     }
     }

protected function _prepareColumns(){
   $color = Mage::getModel('eav/config')->getAttribute('customer', 'color_customer');
   $options = $color->getSource()->getAllOptions(false);
   $colors = array();
   foreach ($options as $option)
   {
       $colors[$option['value']] = $option['label'];
   }
    $this->addColumnAfter('color_customer', array(
        'header'    => Mage::helper('customer')->__('Fav Color'),
        'width'     => '80px',
        'index'     => 'color_customer',
        'type'      => 'options',
        'options'   => $colors
    ),'email');
    return parent::_prepareColumns();
  }
最新回復
  • 2019-12-5
    1 #

    你可以得到這樣的選項:

    $color = Mage::getModel('eav/config')->getAttribute('customer', 'color_customer');
    $options = $color->getSource()->getAllOptions(false);
    

    你接缝让它為其餘部分弄清楚。

  • magento2:將自定義css添加到主题
  • magento 1.7:PayPal故障還是Hack? 付款轉到隨機地址