Post by wackyracer8 » Sat Mar 17, 2018 10:10 pm

OC 3.0.2.0
When an order gets emailed, the sort order for product options are in a random order even though they have been set to a specific order in the product options section within the admin. I need the emailed order to have the same sort order as it shows on the website and checkout. How can this be done please?

Thanks

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by straightlight » Sat Mar 17, 2018 11:24 pm

In catalog/controller/mail/order.php file,

find all instances of:

Code: Select all

$order_options = $this->model_checkout_order->getOrderOptions($order_info['order_id'], $order_product['order_product_id']);
replace all with:

Code: Select all

$order_options = $this->model_checkout_order->getOrderOptions($order_info['order_id'], $order_product['order_product_id'], $order_product['product_id']);
In catalog/model/checkout/order.php file,

replace:

Code: Select all

public function getOrderOptions($order_id, $order_product_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'");
		
		return $query->rows;
	}
with:

Code: Select all

public function getOrderOptions($order_id, $order_product_id, $product_id) {
		$product_option_data = array();
		
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'");
		
		foreach ($query->rows as $order_option) {
			$order_product = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` WHERE `order_product_id` = '" . (int)$order_product_id . "' AND `order_id` = '" . (int)$order_id . "' AND `product_id` = '" . (int)$product_id . "'");
			
			if ($order_product->num_rows) {
				$product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "option_description od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.sort_order");

				foreach ($product_option_query->rows as $product_option) {
					$product_option_value_data = array();

					$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_id = '" . (int)$product_id . "' AND pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.sort_order");

					foreach ($product_option_value_query->rows as $product_option_value) {
						$product_option_value_data[] = array(
							'product_option_value_id' => $product_option_value['product_option_value_id'],
							'option_value_id'         => $product_option_value['option_value_id'],
							'name'                    => $product_option_value['name'],
							'image'                   => $product_option_value['image'],
							'quantity'                => $product_option_value['quantity'],
							'subtract'                => $product_option_value['subtract'],
							'price'                   => $product_option_value['price'],
							'price_prefix'            => $product_option_value['price_prefix'],
							'weight'                  => $product_option_value['weight'],
							'weight_prefix'           => $product_option_value['weight_prefix']
						);
					}

					$product_option_data[] = array(
						'product_option_id'    => $product_option['product_option_id'],
						'product_option_value' => $product_option_value_data,
						'option_id'            => $product_option['option_id'],
						'name'                 => $product_option['name'],
						'type'                 => $product_option['type'],
						'value'                => $product_option['value'],
						'required'             => $product_option['required']
					);
				}
			}

			return $product_option_data;
		}
	}
Last edited by straightlight on Mon Mar 19, 2018 5:13 am, edited 3 times in total.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by wackyracer8 » Sun Mar 18, 2018 9:39 pm

Thanks Straightlight, unfortunately this didn't quite work and instead duplicated the options lots of different times, please see below...

Code: Select all

Any 2 Large Pizzas Only £17.99
  - Add Topping(s) to 1st Pizza: BBQ Chicken
  - Add Topping(s) to 1st Pizza: BBQ Chicken
  - Add Topping(s) to 1st Pizza: BBQ Chicken
  - Add Topping(s) to 2nd Pizza: Spicy Chicken
  - First Pizza: Simply Classic
  - First Pizza: Simply Classic
  - Second Pizza: Simply Classic
Last edited by wackyracer8 on Mon Mar 19, 2018 3:59 am, edited 1 time in total.

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by straightlight » Sun Mar 18, 2018 10:54 pm

My post has now been edited above. See if the new modifications fixes the loops.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by wackyracer8 » Mon Mar 19, 2018 3:42 am

I've just tried this and unfortunately this is still giving me the same kind of result.

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by straightlight » Mon Mar 19, 2018 3:45 am

Ensure to clear your OC cache from the admin before retrying.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by wackyracer8 » Mon Mar 19, 2018 3:46 am

Ok, will try that now, thank you.

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by wackyracer8 » Mon Mar 19, 2018 3:50 am

I've gone into the dashboard and cleared the cache for theme and sass, these were both set to off. The loop has stopped but unfortunately they still arn't in order :(

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by wackyracer8 » Mon Mar 19, 2018 4:16 am

I've been looking at other posts on the forum and noticed Qphoria provided a vqmod for 1.5x and 2x that seemed to address the issue I'm trying to solve. I'fe asked if he has a 3x update but he hasn't replied yet. Do you think I could use something like this for 3x?
viewtopic.php?f=131&t=155395&p=717698#p717698

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by straightlight » Mon Mar 19, 2018 4:20 am

By leaving the replaced codes as it is in your order model, see if the following next step will take effect.

In catalog/controller/mail/order.php file,

find all instances of:

Code: Select all

$data['products'][] = array(
add above:

Code: Select all

$sort_order = array();
			
			foreach ($option_data as $key => $value) {
				$sort_order[$key] = $value;
			}
			
			array_multisort($sort_order, SORT_ASC, $option_data);
Clear your OC cache again afterwards.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by wackyracer8 » Mon Mar 19, 2018 4:26 am

I've just added the code in the 2 places where

Code: Select all

$data['products'][] = array(
is but it still puts the product options in a random order :(
I also cleared both cache before retrying a new order.
I also have the new piece of code in the above file that you gave me to replace.

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by straightlight » Mon Mar 19, 2018 4:30 am

Have you also cleared your OC cache from the admin - > extensions - > modifications - > refresh button?
Both locations must be used at all times when modifying either PHP and / or TWIG files.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by wackyracer8 » Mon Mar 19, 2018 4:39 am

I didn't. I have just cleared the cache in dashboard and modifications and it still in a random order though.

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by straightlight » Mon Mar 19, 2018 4:46 am

Are you retrying to send an email with the order or you are just reviewing the same invoice of the last order?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by wackyracer8 » Mon Mar 19, 2018 4:49 am

I am putting a new order through the website each time. The invoice that comes through on the email doesn't have the product options in the right order.

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by straightlight » Mon Mar 19, 2018 5:13 am

Revert the changes from: viewtopic.php?f=202&t=202985#p717701 and re-apply the new steps from this post: viewtopic.php?f=202&t=202985#p717620 . I have modified the steps.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by wackyracer8 » Mon Mar 19, 2018 5:27 am

When running a test order on this, when I press the button to checkout to complete the order I get the following error...
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

OK

<b>Warning</b>: Missing argument 3 for ModelCheckoutOrder::getOrderOptions(), called in /home/account-name/public_html/order-online/vqmod/vqcache/vq2-catalog_model_checkout_order.php on line 368 and defined in <b>/home/account-name/public_html/order-online/vqmod/vqcache/vq2-catalog_model_checkout_order.php</b> on line <b>246</b><b>Notice</b>: Undefined variable: product_id in <b>/home/account-name/public_html/order-online/vqmod/vqcache/vq2-catalog_model_checkout_order.php</b> on line <b>252</b>{"redirect":"https:\/\/website.com\/order-online\/index.php?route=checkout\/success"}

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by straightlight » Mon Mar 19, 2018 5:41 am

The three parameters are there in my code above. However, there was a slight mistake during my latest reply which I had to quickly fix. Perhaps it was between that small period where you tried the code (which is fine). Please redo the process on that post. Apologize for the small typo.

Clear your OC cache each times.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by wackyracer8 » Mon Mar 19, 2018 5:55 am

I still get an error, please see below.
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

OK

<b>Warning</b>: Missing argument 3 for ModelCheckoutOrder::getOrderOptions(), called in /home/account/public_html/order-online/vqmod/vqcache/vq2-catalog_model_checkout_order.php on line 368 and defined in <b>/home/account/public_html/order-online/vqmod/vqcache/vq2-catalog_model_checkout_order.php</b> on line <b>246</b><b>Notice</b>: Undefined variable: product_id in <b>/home/account/public_html/order-online/vqmod/vqcache/vq2-catalog_model_checkout_order.php</b> on line <b>252</b>{"redirect":"https:\/\/website.com\/order-online\/index.php?route=checkout\/success"}
The email does come through but it freezes the checkout page. The invoice comes but it leaves the product option value blank, please see below. These are now in the right order though.
Any 2 Medium Pizzas Only £15.99
- First Pizza:
- Add Topping(s) to 1st Pizza:
- Second Pizza:
- Add Topping(s) to 2nd Pizza:
Last edited by wackyracer8 on Mon Mar 19, 2018 6:39 am, edited 2 times in total.

Active Member

Posts

Joined
Fri May 13, 2011 1:15 am

Post by straightlight » Mon Mar 19, 2018 5:57 am

The third parameter is in my post. Are you sure to have replaced all instances from catalog/controller/mail/order.php and in your catalog/model/checkout/order.php file? Sounds like you may have forgot one step or you did not cleared all OC cache ...

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 256 guests