duanoucuo7045 2016-08-10 11:21
浏览 36

Magento更改订单产品行内的属性

I want to change the default SKU attribute (product number) inside the orderview, at the items block, to a custom attribute.

See:

enter image description here

Currently by default the SKU is displayed, I want to change this into the DPN (my custom created attribute).

The attribute code for this is: dpn.

How can I achieve that?

I edit the file:

/app/code/core/Mage/Adminhtml/Block/Sales/Items/Column/Default.php

From default code:

public function getSku()
{
    /*if ($this->getItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
        return $this->getItem()->getProductOptionByCode('simple_sku');
    }*/
    return $this->getItem()->getSku();
}

To:

public function getSku()
{
    /*if ($this->getItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
        return $this->getItem()->getProductOptionByCode('simple_sku');
    }*/
    return $this->getItem()->getDpn();
}

But that does not work. When I change the value to return $this->getItem()->getProductId(); Then I get the Product Id, so that does work.

How can I get the data from the attribute?

  • 写回答

1条回答 默认 最新

  • dongxietao0263 2016-08-22 19:13
    关注

    Order item (sales/order_item) is not the same object as Product (catalog/product). Instead, order item is more like a snapshot of a product when order was created.

    This allows order items to be accessible (from customer order history page or admin panel) and unchanged even after their related product has been deleted or changed.

    Magento, first creates Quote item (sales/quote_item) by 'snapshotting' product added to cart. Eventually Quote item gets converted to Order item.

    In order to complete your task, you need to create new Quote item attribute, and convert the attribute to Order item (optionally, you can further convert it to sales/invoice_item and sales/creditmemo_item).

    To convert attribute form Quote item to Order item, read about Magento <fieldset> config element.

    Alternative, less optimal, solution: You can use your order item to fetch product and use product's attribute value on order view page:

    public function getSku()
    {
       return $this->getItem()->getProduct()->getDpn();
    }
    

    Keep in mind that if you change attribute value for your product, value will be change on all order view pages as well.

    评论

报告相同问题?

悬赏问题

  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器