0

我试图在 onepage.php 中获取产品详细信息,但我失败了。我已经尝试了很多代码,但我没有得到它。我需要使用会话来获取它吗?有人知道代码我如何在 onepage.php 页面中获取产品详细信息?

好的,首先,当我单击购买产品时,它重定向到结帐/购物车/,这意味着在此页面中的 cart.phtml 和 cart.php 我有产品名称 price qauntity 总计。好的,在我单击 Procced 结帐后,它重定向到 checkout/onepage/ ... onepage.php 和 onepage.phtml

好的,现在我在 onepage.php 中设置了一个电子邮件,每当用户在 onepage.php 加载时从购物车页面单击 Procced to checkout 按钮时,它都会发送电子邮件。

现在在电子邮件中,我想添加产品详细信息,例如产品名称数量公司名称。在这里,我已完成所有步骤,但无法获取产品详细信息。该产品将是用户选择进行结帐的产品。

here is my simple email template:
    $to = "$email";
    $from = "test@test.com";
    $subject = "email test";
    //begin of HTML message
    $message = <<<EOF
<html>
  <body bgcolor="#DCEEFC">
    <center>
        <b>email test</b> <br>
        <h1><font color="red">Your Coupon Code:</font>$letters$random_chars<br></h1>

<h1>Product Name : $productname</h1>
<h1>Company Name : $comname</h1>
    </center>

  </body>
</html>
EOF;
$headers  = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";


mail($to, $subject, $message, $headers);

好吧,所以我在这里发送了电子邮件,它的工作正常只需要包含产品名称和公司名称,但我不知道我将如何得到它?

4

1 回答 1

0

结帐时可用的产品不包含所有属性。您应该定义结帐/购物车部分可用的属性config.xml

<sales>
  <quote>
    <item>
      <product_attributes>
        <product_attribute_1/>
        <product_attribute_2/>
      </product_attributes>
    </item>
  <quote>
<sales>

诀窍属于来自 Brim LLC 的 Tim Milhouse

编辑: 在交易电子邮件中包含变量...假设您创建了一个产品属性,即名称product_origin

  • 创建交易电子邮件模板并修改如下:
<html>
   <h1>Dear {{htmlescape var=$order.getCustomerName()}}</h1>
   <p>Thank you choosing {{var store.getFrontendName()}}</p>
   <h2>Here is the order details</h2>
   {{block type='core/template' area='frontend' template='/emails/product_info.phtml' order=$order}}
</html>
  • 创建产品模板product_info.phtml
# File path : /app/design/frontend/[YOUR_NAMESPACE]/[YOUR_THEME]/template/emails/product_info.phtml
 <?php $_order = $this->getOrder(); ?>
 <table>
   <tr>
     <td>Product Name</td>
     <td>Price</td>
     <td>Product Origin (Attribute)</td>
   </tr>
   <?php foreach($_order->getAllItems() as $_item): ?>
   <tr>
     <td><?php echo $_item->getName() ?></td>
     <td><?php echo $_order->formatPrice($_item->getPrice()) ?></td>
     <td>
        <?php
           $_product = Mage::getModel('catalog/product');
           $_product ->load($_item->getProductId());
           echo $_product->getProductOrigin(); // product attribute, if attribute name productorigin, therefore should be getProductorigin
        ?>
     </td>
   </tr>
   <?php endforeach ?>
 </table>
于 2012-03-15T07:10:35.427 回答