Php 嵌套的foreach不能按计划工作,复制第一个数组中的所有内容。(预付发票)

Php 嵌套的foreach不能按计划工作,复制第一个数组中的所有内容。(预付发票),php,arrays,foreach,prestashop,prestashop-1.6,Php,Arrays,Foreach,Prestashop,Prestashop 1.6,我正在尝试为Prestashop创建一个函数,它添加了一个提醒费,并将状态从发票更改为提醒。逾期未付的发票。 下面的代码在选择日期间隔的上一步之后处理请求。 这就像一个魅力,然而,我被困在这里 foreach($order\u invoice\u collection as$invoice)应该为每个订单添加一个名为“提醒费”的产品,但它会在每个订单上不断添加多个产品(与数组中的订单总数相同) 我需要这样做,因为这是我查看如何访问正确的id\u order\u invoice的唯一方法 我真的很

我正在尝试为Prestashop创建一个函数,它添加了一个提醒费,并将状态从发票更改为提醒。逾期未付的发票。 下面的代码在选择日期间隔的上一步之后处理请求。 这就像一个魅力,然而,我被困在这里

foreach($order\u invoice\u collection as$invoice)
应该为每个订单添加一个名为“提醒费”的产品,但它会在每个订单上不断添加多个产品(与数组中的订单总数相同)

我需要这样做,因为这是我查看如何访问正确的
id\u order\u invoice
的唯一方法

我真的很感激这里的任何帮助

public function processGenerateInvoicesPDF6() {
    // switch do update ON/OFF
    $should_update = Tools::getValue("should_update");
    // end switch
    $order_numbers = explode(",", Tools::getValue("order_ids"));

    if(strpos(Tools::getValue("order_ids"),'-') !== false) {
        $order_numbers = explode("-", Tools::getValue("order_ids"));
        $order_numbers = range($order_numbers[0], $order_numbers[1]);
    }
    $order_invoice_collection = array();
    foreach($order_numbers as $order_number) {
        if($order_number != "") {
            $order = new Order($order_number);
            // Switch
            if($should_update) {
                // switch
                $order->current_state += 1;
                $order->total_paid_tax_incl += 60;
                $order->total_paid_tax_excl += 60;
                $order->total_paid += 60;
                $order->update();

               if(is_array($order_invoices = $order->getInvoicesCollection()->getResults())) {
                   $order_invoice_collection = array_merge($order_invoices, $order_invoice_collection); }

                   foreach($order_invoice_collection as $invoice) {
                       $order_detail = new OrderDetail();
                       $order_detail->id_order = $order->id;
                       $order_detail->id_order_invoice = $invoice->id;
                       $order_detail->product_name = "Påminnelseavgift";
                       $order_detail->id_shop = 1;
                       $order_detail->product_id = 999999;
                       $order_detail->product_quantity = 1;
                       $order_detail->product_quantity_in_stock = 1;
                       $order_detail->tax_name = "";
                       $order_detail->product_weight = 0;
                       $order_detail->id_warehouse = 0;
                       $order_detail->product_price = 60;
                       $order_detail->total_price_tax_incl = 60;
                       $order_detail->total_price_tax_excl = 60;
                       $order_detail->unit_price_tax_excl = 60;
                       $order_detail->unit_price_tax_incl = 60;
                       $order_detail->save();
                    }
                    $orderHistory = new OrderHistory();
                    $orderHistory->id_order = $order->id;
                    $orderHistory->id_order_state = $order->current_state;
                    $datetime = date('Y-m-d H:i:s');
                    $orderHistory->date_add = pSQL($datetime);
                    $orderHistory->save();
                    //end test switch
                }
                // end test switch
            }
        }

        if(count($order_invoice_collection) == 0) {
            Tools::redirectAdmin($this->context->link->getAdminLink('AdminInvoices'));
        }

        $this->generatePDF($order_invoice_collection, PDF::TEMPLATE_INVOICE);
    }
}

我不知道你为什么把它弄得这么复杂,但是你已经嵌套了两个
foreach
,所以
$order\u invoice\u collection
在每个循环中都会变大,bacame翻了一番,因为
$order\u invoice\u collection=array()在这些循环之外。我建议您制作一个特殊的
订单状态
,并在使用hook
actionOrderStatusUpdate
更改此
订单状态时指定提醒费。我在prestashop还是个新手,您能为我指出正确的方向吗@我将不胜感激!你需要从这里和这里开始。我不知道你为什么要把它弄得这么复杂,但是你已经嵌套了两个
foreach
,所以
$order\u invoice\u collection
在每个循环中都会变大,bacame加倍,因为
$order\u invoice\u collection=array()在这些循环之外。我建议您制作一个特殊的
订单状态
,并在使用hook
actionOrderStatusUpdate
更改此
订单状态时指定提醒费。我在prestashop还是个新手,您能为我指出正确的方向吗@我将不胜感激!你需要从这里和这里开始。