4

项目

修改 Magento 的电子邮件模板以包含长描述

Magento 版本

1.6.2.0

正在编辑的文件

app/design/frontend/default/<template name>/template/email/order/items/order/default.phtml

此文件中带有行号的感兴趣代码:

31 <strong style="font-size:11px;"><?php echo $this->htmlEscape($_item->getName()) ?></strong>
46 <?php echo $this->escapeHtml($_item->getDescription()) ?>

问题

$_item -> getName()有效,但$_item -> getDescription()返回 null

调试

$_item的 Zend 转储(显示定义的“名称”;“描述”为空):

array(79) {
["item_id"] => string(3) "584"
["order_id"] => string(3) "398"
["parent_item_id"] => NULL
["quote_item_id"] => string(4) "1951"
["store_id"] => string(1) "1"
["created_at"] => string(19) "2012-06-04 14:15:39"
["updated_at"] => string(19) "2012-06-04 14:16:18"
["product_id"] => string(3) "156"
["product_type"] => string(6) "simple"
["product_options"] => string(140) "a:1:{s:15:"info_buyRequest";a:3:{s:4:"uenc";s:48:"aHR0cDovL2Rldi5hcHBvZ2VlLmNvbS9iYXNlL21hYy5odG1s";s:7:"product";s:3:"156";s:3:"qty";i:1;}}"
["weight"] => string(6) "0.0100"
["is_virtual"] => string(1) "0"
["sku"] => string(9) "MC969LL/A"
["name"] => string(21) "11" MacBook Air 128GB"
["description"] => NULL
["applied_rule_ids"] => NULL
["additional_data"] => NULL
["free_shipping"] => string(1) "0"
["is_qty_decimal"] => string(1) "0"
["no_discount"] => string(1) "0"
["qty_backordered"] => NULL
["qty_canceled"] => string(6) "0.0000"
["qty_invoiced"] => string(6) "0.0000"
["qty_ordered"] => string(6) "1.0000"
["qty_refunded"] => string(6) "0.0000"
["qty_shipped"] => string(6) "1.0000"
["base_cost"] => NULL
["price"] => string(9) "1199.0000"
["base_price"] => string(9) "1199.0000"
["original_price"] => string(9) "1199.0000"
["base_original_price"] => string(9) "1199.0000"
["tax_percent"] => string(6) "7.0000"
["tax_amount"] => string(7) "83.9300"
["base_tax_amount"] => string(7) "83.9300"
["tax_invoiced"] => string(6) "0.0000"
["base_tax_invoiced"] => string(6) "0.0000"
["discount_percent"] => string(6) "0.0000"
["discount_amount"] => string(6) "0.0000"
["base_discount_amount"] => string(6) "0.0000"
["discount_invoiced"] => string(6) "0.0000"
["base_discount_invoiced"] => string(6) "0.0000"
["amount_refunded"] => string(6) "0.0000"
["base_amount_refunded"] => string(6) "0.0000"
["row_total"] => string(9) "1199.0000"
["base_row_total"] => string(9) "1199.0000"
["row_invoiced"] => string(6) "0.0000"
["base_row_invoiced"] => string(6) "0.0000"
["row_weight"] => string(6) "0.0100"
["base_tax_before_discount"] => NULL
["tax_before_discount"] => NULL
["ext_order_item_id"] => NULL
["locked_do_invoice"] => NULL
["locked_do_ship"] => NULL
["price_incl_tax"] => string(9) "1282.9300"
["base_price_incl_tax"] => string(9) "1282.9300"
["row_total_incl_tax"] => string(9) "1282.9300"
["base_row_total_incl_tax"] => string(9) "1282.9300"
["hidden_tax_amount"] => NULL
["base_hidden_tax_amount"] => NULL
["hidden_tax_invoiced"] => NULL
["base_hidden_tax_invoiced"] => NULL
["hidden_tax_refunded"] => NULL
["base_hidden_tax_refunded"] => NULL
["is_nominal"] => string(1) "0"
["tax_canceled"] => NULL
["hidden_tax_canceled"] => NULL
["tax_refunded"] => NULL
["gift_message_id"] => NULL
["gift_message_available"] => string(1) "0"
["base_weee_tax_applied_amount"] => string(6) "0.0000"
["base_weee_tax_applied_row_amnt"] => string(6) "0.0000"
["base_weee_tax_applied_row_amount"] => string(6) "0.0000"
["weee_tax_applied_amount"] => string(6) "0.0000"
["weee_tax_applied_row_amount"] => string(6) "0.0000"
["weee_tax_applied"] => string(6) "a:0:{}"
["weee_tax_disposition"] => string(6) "0.0000"
["weee_tax_row_disposition"] => string(6) "0.0000"
["base_weee_tax_disposition"] => string(6) "0.0000"
["base_weee_tax_row_disposition"] => string(6) "0.0000"
}

问题

为什么这里的描述为空?

我发现在下订单后更改产品名称不会更改订单中的名称,因此订单对象似乎在订购的产品上有自己的数据,该数据与实时目录分开(我想有道理:您希望该信息是静态且不可更改的)。

由于浪费了数据库中的空间,它不会在每次订购商品时尝试存储商品的长和/或短描述也是有道理的。但是为什么要包含描述字段只是为了将其留空?

我获取该信息以加载目录/产品模型、找到我想要的产品和属性的唯一方法是(就像这里)?

4

1 回答 1

4

你在所有方面都是正确的。我不知道他们为什么包含该description字段,但在我所有的 250,000 个订单中它都是空的。

您可以通过以下方法获取描述:

$_description = Mage::getModel('catalog/product')
    ->load($_item->getProductId())
    ->getDescription();

null如果产品已被删除,这很可能会返回。

于 2012-06-05T16:53:44.763 回答