添加更多信息到 Magento 装箱单或发票 PDF

发布于 2024-10-17 11:53:44 字数 785 浏览 2 评论 0原文

我如何向 Magento 装箱单 PDF 添加附加信息。我使用的是集成标签纸,因此我想在页脚添加重复的客户送货地址,以及一些详细信息,例如订单中的商品总数和订单中商品的成本。我目前正在修改本地文件:Mage/Sales/Model/Order/Pdf/,但我只能更改字体。

编辑:

好的,我已经取得了良好的进展,并添加了我需要的大部分信息,但是,我现在偶然发现了一个问题..我想获得每个订单和数量中所有物品的总重量。

我在shipment.php中使用此代码:

在foreach下(这在订单有拆分交付的情况下很有用 - 因为您可以有一个订单有多个“发货”所以这就是为什么我在这里有代码:

foreach ($shipment->getAllItems() as $item){
    if ($item->getOrderItem()->getParentItem()) {
        continue;
...

然后我还有这个:

$shippingweight=0;
$shippingweight= $item->getWeight()*$item->getQty();
$page->drawText($shippingweight . Mage::helper('sales'), $x, $y, 'UTF-8');

这对于行总计来说非常有用,但对于整个货件来说却不是这样,我需要做的是为货件中的每个项目“添加”这段代码以创建整个货件的总重量。非常重要的是,我只有发货总量,而不是订单,因为我将拆分发货。

How can i add additional information to the Magento Packingslip PDF. I am using integrated label paper, so i would like to add repeat the customers delivery address at the footer and also, some details like total quantity of items in the order and the cost of the items in the order. I am currently modifying local files in: Mage/Sales/Model/Order/Pdf/ but I have only managed to change to font.

EDIT:

Okay, i have made good progress and added most of the information i need, however, i have now stumbled across a problem.. I would like to get the total weight of all items in each order and Quantity.

I am using this code in the shipment.php:

Under the foreach (This is useful in case an order has a split delivery - as you can have one order with multiple "shipments" So this is why I have the code after here:

foreach ($shipment->getAllItems() as $item){
    if ($item->getOrderItem()->getParentItem()) {
        continue;
...

then I have this further down:

$shippingweight=0;
$shippingweight= $item->getWeight()*$item->getQty();
$page->drawText($shippingweight . Mage::helper('sales'), $x, $y, 'UTF-8');

This is great for Row totals. But not for the whole shipment. What I need to do is have this bit of code "added up" for each item in the shipment to create the total Weight of the whole shipment. It is very important that I only have the total of the shipment - not the order as I will be splitting shipments.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宁愿没拥抱 2024-10-24 11:53:44

几乎在 Mage_Sales_Model_Order_Pdf_ShipmentgetPdf(...) 的末尾,您会发现插入新页面的代码(1.5.0.1 中的第 93-94 行)

if($this->y<15)
   $page = $this->newPage(....)

发生在 for 中-环形。

您可以更改此处的逻辑,使其提前换页,为您的额外信息腾出空间,然后在换页之前将其添加。如果您希望代码也出现在最后一页上,您还应该将代码放在 for 块之后。

注意:您不应直接更改 app/code/code/Mage 中的文件。相反,您应该使用相同的文件夹结构将更改的文件放置在 app/code/local/Mage 下。这样您的更改就不会在升级中意外被覆盖。

这应该可以得到订单中的商品总数(可能有更快的方法,但我不知道):

$quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
$itemsCount = $quote->getItemsSummaryQty();

Almost at the end of getPdf(...) in Mage_Sales_Model_Order_Pdf_Shipment you will find the code that inserts new pages (lines 93-94 in 1.5.0.1)

if($this->y<15)
   $page = $this->newPage(....)

happening in a for-loop.

You can change the logic here to make it change page earlier to make room for your extra information and then add it before the page shift. You should also place code after the for-block if you want it to appear on the last page as well.

Note: You should not change files in app/code/code/Mage directly. Instead, you should place your changed files under app/code/local/Mage using the same folder structure. That way your changes won't accidently get overwritten in an upgrade.

This should get you the total number of items in your order (there might be a faster way but don't know it off the top of my head):

$quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
$itemsCount = $quote->getItemsSummaryQty();
兔小萌 2024-10-24 11:53:44

发票 PDF

位于 app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
在 $lineBlock 之前添加此内容

 $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getSku($item), array('weight'));

     $lines[][] = array(
       'text'  => 'Weight: '. $product->getData('weight')*1 .'Kg/ea.  Total: ' .$product->getData('weight')*$item->getQty() . 'Kg',
       'feed'  => 400
      );

For invoice PDF

at app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
add this before $lineBlock

 $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getSku($item), array('weight'));

     $lines[][] = array(
       'text'  => 'Weight: '. $product->getData('weight')*1 .'Kg/ea.  Total: ' .$product->getData('weight')*$item->getQty() . 'Kg',
       'feed'  => 400
      );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文