How to add your code to the page in Opencart?

I have code which runs on the page "index.php?route=checkout/success" here it is:
foreach ($data['products'] as $product) {
 $viberText = "";
 $bitrix24products = "";
 $prodId = $product['product_id'];
 $order_mpn = $this->db->query("SELECT `mpn` FROM `" . DB_PREFIX . "product` WHERE `product_id` = '$prodId'");
 $order_mpn = $order_mpn->row["mpn"];
 $bitrix24option = empty($product['option']) ? "" : "<br/><br/><b>Options:</b>";
 $viberTextOption = empty($product['option']) ? "" : "Options: \n";
 $bitrix24products .= 
 "<b>Title:</b> ".$product['name']." (<a target='_blank' href='http://".$_SERVER['HTTP_HOST']."/index.php?route=product/product&product_id=".$product['product_id']."'>Ssylka</a>)".
 "<br/><b>Quantity:</b> ".$product['quantity']." PCs".
 "<br/><b>Price:</b> ".$product['price']." UAH".
 "<br/><b>Amount:</b> ".$product['total']." UAH".
 "<br/><b>Vendor:</b> ".$order_mpn.

 $viberText .="\nazvanie:\n".$product['name'].
 "\kolichestvo:".$product['quantity']." PCs".
 "\price::". $product['price']." UAH".
 "\Summa: ".$product['total']." UAH".$viberTextOption;

 foreach ($product['option'] as $option) {
 if ($option['type'] == 'checkbox') {
 $bitrix24products .= "<br/>-- Selected: ".$option['name'];
 $viberText .= "\wybrano: ".$option['name'];
 } else {
 $bitrix24products .= "<br/>-- ".$option['name'].": ".$option['value'];
 $viberText .= "\n".$option['name'].": ".$option['value'];

 if ($product != end($data['products'])) {
 $bitrix24products .= "<br/><br/>------------------------------------------------<br/><br/>";
 $viberText .= "\n";
 } else {
 $bitrix24products .= "<br/>";
 $viberText .= "\n";
 $stack[$order_mpn] .= $viberText;
 $stackBitrix[$order_mpn] .= $bitrix24products;

He used to run on the index page.php?route=checkout/checkout, after which I Pernes this code on need stranicu. After migration, you receive the error: "Notice: Undefined index: products in /var/www/www-root/data/www/" How can I fix this?
April 4th 20 at 00:43
2 answers
April 4th 20 at 00:45
It is difficult to say otrivine Cuzco code, and opencart deeds of long ago had, but the error is quite typical for opencart and it occurs for all users.
the array $data has no key 'products', most likely you are either not suffered, or too overdone, trace the variable in the old version and the new.
Alternatively, the products may have previously been taken out of the basket when it was available on the stage (checkout/checkout) and now possibly may have to be taken from the tables of the order (checkout/success)
I realized, due to the fact that the basket is empty, to fail to do so, and then on the button "order Confirmation" to do so after pressing it the code was executed, such as here on the button "checkout", and in General where is this button? - maybell_Bashirian commented on April 4th 20 at 00:48
In fact the piece of code is not particularly nitchevo not depends on Your site if you want to quickly close the issue, I would query the table (oc_)order_product and would have found all products by order_id - which ideas you should have known
$this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '$orderId'");

instead of $orderId to put the real variable with a warrant
and in loops instead of $data['products'] use the result of this query.
Not only the convenience of this option, they will have to take from the table oc_order_option well, there can be pageunit to the previous query or the variant is easier to do additional query before the loop, I think to buy a lot of products will not be so load will not be strong - edwina_Ullri commented on April 4th 20 at 00:51
@edwina_Ullri, I got rid of the code), I still need to take customer data and also to process, so much better to do it on the button of the order confirmation, the page where the shopping cart is still not empty yet, but I can't find the function and file which handles this button. I'm new to OS) - maybell_Bashirian commented on April 4th 20 at 00:54
I looked in the old project (most likely I have a different version of opencart)
confirmation is the file confirm.php (in the same folder checkout), and looked at success there is a possibility that the basket hasn't been emptied and cleaned can try to adapt your code before clearing the basket - edwina_Ullri commented on April 4th 20 at 00:57
before foreach ($data['products'] as $product) {

do var_dump($data);
most likely you do not have the array of these data.
it happens if you forgot for example to load the model in the controller.

poked here or there - Zita commented on April 4th 20 at 01:00
@edwina_Ullri, I also Have a file confirm.php. I understand,after clicking the "checkout" function is executed from this file? Or how does it work? - maybell_Bashirian commented on April 4th 20 at 01:03
well, that's not quite what You need but Yes, after that you are going to pay for the selected payment and now he decides to name on success, or return back in case of not success - edwina_Ullri commented on April 4th 20 at 01:06
@edwina_Ullri, I understand, thank you very much) - maybell_Bashirian commented on April 4th 20 at 01:09
April 4th 20 at 00:47
To create a module

Find more questions by tags OpenCart