Post by Majnoon » Wed Jun 29, 2022 8:06 pm

Hi Guys,
I am using OC 3.0.3.5 and want to record extra field for oc_order_product table.
In admin/controller/sale/order.php

Code: Select all

// Products
			$data['order_products'] = array();

			$products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']);

			foreach ($products as $product) {
				$data['order_products'][] = array(
					'product_id' => $product['product_id'],
					'name'       => $product['name'],
					'model'      => $product['model'],
					'option'     => $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']),
					'quantity'   => $product['quantity'],
					'price'      => $product['price'],
					'total'      => $product['total'],
					'reward'     => $product['reward']
				);
			}
I can define

Code: Select all

   'mpn'	=>$product['mpn'] 
and can
ALTER TABLE oc_order_product ADD mpn VARCHAR (12) NOT NULL;
Question
How can i pull this value without showing it on checkout? So when customer place an order i should have the value for mpn as well along with others.
p.s: mpn value will be declared when adding/editing the product.

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by paulfeakins » Wed Jun 29, 2022 9:57 pm

If you don't know these sorts of things, shouldn't you consider hiring a developer to modify the checkout of your online shop?

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by Majnoon » Wed Jun 29, 2022 11:29 pm

paulfeakins wrote:
Wed Jun 29, 2022 9:57 pm
If you don't know these sorts of things, shouldn't you consider hiring a developer to modify the checkout of your online shop?
Off-course i do have knowledge of SQL and PHP its just new to Opencart hence asking a question wont hurt.
If you can answer the question then Thank you if not then no hard feelings. Have a great day ahead :-*

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by pprmkr » Thu Jun 30, 2022 4:33 pm

MPN is available in product, but is not used/stored in order.
First make sure 'mpn' is stored in order_product table:

Code: Select all

	<file path="catalog/model/checkout/order.php">
		<operation>
			<search><![CDATA[, model = '" . $this->db->escape($product['model']) . "']]></search>
			<add position="replace"><![CDATA[, model = '" . $this->db->escape($product['model']) . "', mpn = '" . $this->db->escape($product['mpn']) . "']]></add>
		</operation>
		<operation>
			<search><![CDATA['model'    => $product['model'],]]></search>
			<add position="after"><![CDATA[
		'mpn' => $product['mpn'],
			]]></add>
		</operation>
	</file>
It has to get value for 'mpn' from library cart:

Code: Select all

	<file path="system/library/cart/cart.php">
		<operation>
			<search><![CDATA[$product_query->row['model'],]]></search>
			<add position="after"><![CDATA[
			'mpn'           => $product_query->row['mpn'],
			]]></add>
		</operation>		
	</file>
Then some modifications to admin order info to show 'mpn':

Code: Select all

	<file path="admin/view/template/sale/order_info.twig">
		<operation>
			<search><![CDATA[{{ column_model }}</td>]]></search>
			<add position="after"><![CDATA[
                <td class="text-left">MPN</td>]]></add>
		</operation>
		<operation>
			<search><![CDATA[{{ product.model }}</td>]]></search>
			<add position="after"><![CDATA[
			    <td class="text-left">{{ product.mpn }}</td>
			]]></add>
		</operation>
		<operation>
			<search><![CDATA[<td colspan="4" class="text-right">{{ total.title }}</td>]]></search>
			<add position="replace"><![CDATA[<td colspan="5" class="text-right">{{ total.title }}</td>]]></add>
		</operation>
	</file>
Just download and install attached ocmod.xml and report back.

Attachments


User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by Majnoon » Fri Jul 01, 2022 8:53 am

Thanks Roelie,
I have added the modification file but in OCMOD error log I can see that
ERROR: CODE NOT FOUND!
FILE: catalog/model/checkout/order.php
CODE: 'model' => $product['model'],
MOD: PprMkr - MPN to Order
Do you mean?

Code: Select all

model = '" . $this->db->escape($product['model']) . "',

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by pprmkr » Fri Jul 01, 2022 1:51 pm

Checked, removed some lines and updated.

Attachments


User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by Majnoon » Fri Jul 08, 2022 6:13 pm

pprmkr wrote:
Fri Jul 01, 2022 1:51 pm
Checked, removed some lines and updated.
This Worked Rolie,
But i wanted to save mpn into oc_order_table in database. So i can pull that data into Reports sections.

Active Member

Posts

Joined
Fri Feb 05, 2021 8:29 pm

Post by pprmkr » Fri Jul 08, 2022 7:30 pm

Now added modifications to extension/report/product_purchased ...

Attachments


User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands
Who is online

Users browsing this forum: sidclel and 84 guests