Post by imcdonald83 » Tue Aug 04, 2020 6:44 pm

Now is see the error of my ways. I have fixed that and the website is good with the updates applied. I will monitor to see if the issue resolves itself.

Newbie

Posts

Joined
Fri Mar 02, 2012 5:17 am

Post by TheJaspMan » Mon Aug 17, 2020 12:58 am

This is a MAJOR problem - as in business traumatizing when you have hundreds of order per day coming and in it happens 1/3 of the time. Enough that our credit card processor reached out in concern. Is there a cleaner fix thread that is clear, direct and locked of other messages?

Exposed Clothing, LLC http://exposedclothing.com


New member

Posts

Joined
Thu Nov 22, 2012 5:09 am

Post by AlanARG » Thu Nov 05, 2020 9:24 pm

letxobnav wrote:
Thu Jun 04, 2020 8:25 am
3) call these functions in register and login controllers
2 function calls for login, giving the current session id to possible old customer items and merging the current guest items
1 function call for register as there cannot be any old customer items so just merging the current guest items

in catalog/controller/checkout/login.php and catalog/controller/account/login.php
just after:

Code: Select all

unset($this->session->data['guest']);
add:

Code: Select all

			// change[662] giving old cart items of the customer the current session id
			$this->cart->renew_session_id_old_items ($this->customer->getId());
			// change[662] assigning the current guest cart items to the customer
			$this->cart->transfer_items_to_new_customer ($this->customer->getId());

in catalog/controller/checkout/register.php and catalog/controller/account/register.php
just after:

Code: Select all

unset($this->session->data['guest']);
add:

Code: Select all

			// change[662] assigning the current guest cart items to the customer
			$this->cart->transfer_items_to_new_customer ($this->customer->getId());

That is all.
Those two are causing an error that doesn't let users to register/login. Website goes straight to some sort of "not found" page but after F5 it works and the user is logged in or in the register process.

Error log shows the following /checkout/login.php:

Code: Select all

[05-Nov-2020 08:58:19 America/Argentina/Buenos_Aires] PHP Fatal error:  Uncaught Error: Call to undefined method Cart\Cart::renew_session_id_old_items() in /home/c1811017/public_html/catalog/controller/checkout/login.php:64
Stack trace:
#0 /home/c1811017/public_html/storage/modification/system/engine/action.php(79): ControllerCheckoutLogin->save()
#1 /home/c1811017/public_html/catalog/controller/startup/router.php(25): Action->execute(Object(Registry))
#2 /home/c1811017/public_html/storage/modification/system/engine/action.php(79): ControllerStartupRouter->index()
#3 /home/c1811017/public_html/system/engine/router.php(67): Action->execute(Object(Registry))
#4 /home/c1811017/public_html/system/engine/router.php(56): Router->execute(Object(Action))
#5 /home/c1811017/public_html/system/framework.php(165): Router->dispatch(Object(Action), Object(Action))
#6 /home/c1811017/public_html/system/startup.php(104): require_once('/home/c1811017/...')
#7 /home/c1811017/public_html/index.php(26): start('catalog')
#8 {main}
  thrown in /home/c1811017/public_html/catalog/controller/checkout/login.php on line 64
/account/login.php:

Code: Select all

[04-Nov-2020 18:59:41 America/Argentina/Buenos_Aires] PHP Fatal error:  Uncaught Error: Call to undefined method Cart\Cart::renew_session_id_old_items() in /home/c1811017/public_html/catalog/controller/account/login.php:56
Stack trace:
#0 /home/c1811017/public_html/storage/modification/system/engine/action.php(79): ControllerAccountLogin->index()
#1 /home/c1811017/public_html/catalog/controller/startup/router.php(25): Action->execute(Object(Registry))
#2 /home/c1811017/public_html/storage/modification/system/engine/action.php(79): ControllerStartupRouter->index()
#3 /home/c1811017/public_html/system/engine/router.php(67): Action->execute(Object(Registry))
#4 /home/c1811017/public_html/system/engine/router.php(56): Router->execute(Object(Action))
#5 /home/c1811017/public_html/system/framework.php(165): Router->dispatch(Object(Action), Object(Action))
#6 /home/c1811017/public_html/system/startup.php(104): require_once('/home/c1811017/...')
#7 /home/c1811017/public_html/index.php(26): start('catalog')
#8 {main}
  thrown in /home/c1811017/public_html/catalog/controller/account/login.php on line 56
checkout and account/register.php:

Code: Select all

[04-Nov-2020 11:51:39 America/Argentina/Buenos_Aires] PHP Fatal error:  Uncaught Error: Call to undefined method Cart\Cart::transfer_items_to_new_customer() in /home/c1811017/public_html/catalog/controller/account/register.php:31
Stack trace:
#0 /home/c1811017/public_html/storage/modification/system/engine/action.php(79): ControllerAccountRegister->index()
#1 /home/c1811017/public_html/catalog/controller/startup/router.php(25): Action->execute(Object(Registry))
#2 /home/c1811017/public_html/storage/modification/system/engine/action.php(79): ControllerStartupRouter->index()
#3 /home/c1811017/public_html/system/engine/router.php(67): Action->execute(Object(Registry))
#4 /home/c1811017/public_html/system/engine/router.php(56): Router->execute(Object(Action))
#5 /home/c1811017/public_html/system/framework.php(165): Router->dispatch(Object(Action), Object(Action))
#6 /home/c1811017/public_html/system/startup.php(104): require_once('/home/c1811017/...')
#7 /home/c1811017/public_html/index.php(26): start('catalog')
#8 {main}
  thrown in /home/c1811017/public_html/catalog/controller/account/register.php on line 31
[04-Nov-2020 13:40:59 America/Argentina/Buenos_Aires] PHP Fatal error:  Uncaught Error: Call to undefined method Cart\Cart::transfer_items_to_new_customer() in /home/c1811017/public_html/catalog/controller/checkout/register.php:240
Stack trace:
#0 /home/c1811017/public_html/storage/modification/system/engine/action.php(79): ControllerCheckoutRegister->save()
#1 /home/c1811017/public_html/catalog/controller/startup/router.php(25): Action->execute(Object(Registry))
#2 /home/c1811017/public_html/storage/modification/system/engine/action.php(79): ControllerStartupRouter->index()
#3 /home/c1811017/public_html/system/engine/router.php(67): Action->execute(Object(Registry))
#4 /home/c1811017/public_html/system/engine/router.php(56): Router->execute(Object(Action))
#5 /home/c1811017/public_html/system/framework.php(165): Router->dispatch(Object(Action), Object(Action))
#6 /home/c1811017/public_html/system/startup.php(104): require_once('/home/c1811017/...')
#7 /home/c1811017/public_html/index.php(26): start('catalog')
#8 {main}
  thrown in /home/c1811017/public_html/catalog/controller/checkout/register.php on line 240
This is how it looks checkout/register.php file after the modifications (line 240):

Code: Select all

unset($this->session->data['guest']);
			// change[662] assigning the current guest cart items to the customer
			$this->cart->transfer_items_to_new_customer ($this->customer->getId());
account/register.php (line 31):

Code: Select all

unset($this->session->data['guest']);
			// change[662] assigning the current guest cart items to the customer
			$this->cart->transfer_items_to_new_customer ($this->customer->getId());
account/login.php (line 56):

Code: Select all

unset($this->session->data['guest']);
						// change[662] giving old cart items of the customer the current session id
						$this->cart->renew_session_id_old_items ($this->customer->getId());
						// change[662] assigning the current guest cart items to the customer
						$this->cart->transfer_items_to_new_customer ($this->customer->getId());
checkout/login.php (line 64):

Code: Select all

unset($this->session->data['guest']);
						// change[662] giving old cart items of the customer the current session id
						$this->cart->renew_session_id_old_items ($this->customer->getId());
						// change[662] assigning the current guest cart items to the customer
						$this->cart->transfer_items_to_new_customer ($this->customer->getId());
I honestly don't know what I did wrong since it doesn't seem too complicated, it was just a copy-paste adding a few small lines of code where you told us. I hope you can help me :)

Thanks!

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

Post by sw!tch » Sat Nov 07, 2020 9:28 am

AlanARG wrote:
Thu Nov 05, 2020 9:24 pm
I honestly don't know what I did wrong since it doesn't seem too complicated, it was just a copy-paste adding a few small lines of code where you told us. I hope you can help me :)

Thanks!
You missed step 1 & 2 ..

Note the cart class changes...

viewtopic.php?f=201&t=211273#p789630

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm
Location - USA

Post by AlanARG » Wed Nov 18, 2020 10:12 am

sw!tch wrote:
Sat Nov 07, 2020 9:28 am
You missed step 1 & 2 ..

Note the cart class changes...

viewtopic.php?f=201&t=211273#p789630
I'm having the same issue as the guy that posted while ago, a HTTP 500 ERROR.

I've placed it after "private $data" like you said and it's inside the "__construct"

This is the final result with the modifications you said:

Code: Select all

<?php
namespace Cart;
class Cart {
	private $data = array();

	public function __construct($registry) {
		$this->config = $registry->get('config');
		$this->customer = $registry->get('customer');
		$this->session = $registry->get('session');
		$this->db = $registry->get('db');
		$this->tax = $registry->get('tax');
		$this->weight = $registry->get('weight');
		
		

		// Remove all the expired carts with no customer ID
		$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE (api_id > '0' OR customer_id = '0') AND date_added < DATE_SUB(NOW(), INTERVAL 1 HOUR)");
		
		public function renew_session_id_old_items ($customer_id) {
		// We want to change the session ID on all the old items in the customers cart
		$sql = "UPDATE " . DB_PREFIX . "cart SET session_id = '" . $this->db->escape($this->session->getId()) . "' WHERE api_id = '0' AND customer_id = '" . (int)$customer_id . "'";
		$this->db->query($sql);
	}
	
	public function transfer_items_to_new_customer ($customer_id) {
		// Once the customer is logged in we want to merge the current guest items with the customer cart and empty the guest cart
		$sql = "SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '0' AND customer_id = '0' AND session_id = '" . $this->db->escape($this->session->getId()) . "'";
		$cart_save_query = $this->db->query($sql);
		foreach ($cart_save_query->rows as $cart) {
			$this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);
			$sql = "DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart['cart_id'] . "'";
			$this->db->query($sql);
		}
	}
		
	}
Thanks a lot man!

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

Post by sw!tch » Wed Nov 18, 2020 10:48 am

AlanARG wrote:
Wed Nov 18, 2020 10:12 am
I'm having the same issue as the guy that posted while ago, a HTTP 500 ERROR.
500 error can be caused by a lot of things. Whats the full error being reported in your server error log?

Maybe PM the member who wrote it for support, clearly the errors being posted are due to improper implementation.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm
Location - USA

Post by AlanARG » Wed Nov 18, 2020 11:26 am

sw!tch wrote:
Wed Nov 18, 2020 10:48 am
AlanARG wrote:
Wed Nov 18, 2020 10:12 am
I'm having the same issue as the guy that posted while ago, a HTTP 500 ERROR.
500 error can be caused by a lot of things. Whats the full error being reported in your server error log?

Maybe PM the member who wrote it for support, clearly the errors being posted are due to improper implementation.
PHP Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /home/c1811017/public_html/system/library/cart/cart.php on line 17
PHP Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /home/c1811017/public_html/system/library/cart/cart.php on line 19

And there's other errors on login.php and register.php (both catalog/controller/checkout and account).

I've tried to send a PM but I think he's profile is blocked. Maybe I can quote him here? @letxobnav
letxobnav wrote:
Sun Apr 21, 2019 11:20 am
a
Any ideas on what's wrong? :)

Thanks for any help!

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

Post by sw!tch » Wed Nov 18, 2020 12:05 pm

AlanARG wrote:
Wed Nov 18, 2020 11:26 am
Any ideas on what's wrong? :)
Yes, the two functions you added are incorrectly implemented.

Code: Select all

public function transfer_items_to_new_customer ($customer_id) { ..}
public function renew_session_id_old_items ($customer_id) { ..}
Your formatting is messed up, these should go into the class not the __construct method.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm
Location - USA

Post by AlanARG » Wed Nov 18, 2020 11:09 pm

sw!tch wrote:
Wed Nov 18, 2020 12:05 pm
AlanARG wrote:
Wed Nov 18, 2020 11:26 am
Any ideas on what's wrong? :)
Yes, the two functions you added are incorrectly implemented.

Code: Select all

public function transfer_items_to_new_customer ($customer_id) { ..}
public function renew_session_id_old_items ($customer_id) { ..}
Your formatting is messed up, these should go into the class not the __construct method.
Like this?

Code: Select all

<?php
namespace Cart;
class Cart {
	private $data = array();
	
	public function renew_session_id_old_items ($customer_id) {
		// We want to change the session ID on all the old items in the customers cart
		$sql = "UPDATE " . DB_PREFIX . "cart SET session_id = '" . $this->db->escape($this->session->getId()) . "' WHERE api_id = '0' AND customer_id = '" . (int)$customer_id . "'";
		$this->db->query($sql);
	}
	
	public function transfer_items_to_new_customer ($customer_id) {
		// Once the customer is logged in we want to merge the current guest items with the customer cart and empty the guest cart
		$sql = "SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '0' AND customer_id = '0' AND session_id = '" . $this->db->escape($this->session->getId()) . "'";
		$cart_save_query = $this->db->query($sql);
		foreach ($cart_save_query->rows as $cart) {
			$this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);
			$sql = "DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart['cart_id'] . "'";
			$this->db->query($sql);
		}
	}

	public function __construct($registry) {
		$this->config = $registry->get('config');
		$this->customer = $registry->get('customer');
		$this->session = $registry->get('session');
		$this->db = $registry->get('db');
		$this->tax = $registry->get('tax');
		$this->weight = $registry->get('weight');
		
		

		// Remove all the expired carts with no customer ID
		$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE (api_id > '0' OR customer_id = '0') AND date_added < DATE_SUB(NOW(), INTERVAL 1 HOUR)");		
	}
This certainly confused me before that's why I placed it there.
letxobnav wrote:
Tue Aug 04, 2020 5:06 pm
no, you have put both functions inside the __construct function.

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

Post by sw!tch » Thu Nov 19, 2020 4:16 am

AlanARG wrote:
Wed Nov 18, 2020 11:09 pm
Like this?
Yes that should work. If you're going for proper class formatting __construct should be first then the two other functions.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm
Location - USA

Post by AlanARG » Thu Nov 19, 2020 6:50 am

sw!tch wrote:
Thu Nov 19, 2020 4:16 am
AlanARG wrote:
Wed Nov 18, 2020 11:09 pm
Like this?
Yes that should work. If you're going for proper class formatting __construct should be first then the two other functions.
That worked! Thanks a lot man! :)

Active Member

Posts

Joined
Mon Feb 22, 2016 6:15 pm

Post by raph7 » Mon Dec 14, 2020 11:50 pm

letxobnav wrote:
Wed Jul 24, 2019 8:03 pm
this one is better, previous one had to many deletes ( delete the saved entries all at once and also in the loop).

Code: Select all

public function transfer_items_to_new_customer ($customer_id) {
		// Once the customer is logged in we want to update the customers cart
		$sql = "SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '0' AND customer_id = '0' AND session_id = '" . $this->db->escape($this->session->getId()) . "'";
		$cart_save_query = $this->db->query($sql);
		foreach ($cart_save_query->rows as $cart) {
			$sql = "DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart['cart_id'] . "'";
			$this->db->query($sql);
			$this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);
		}
	}
I use the separate delete query in the loop so I can better trace it (is what is deleted also added) with an error_log statement if needed.
I did all the steps mentioned on this topic.. But it is still duplicating for me... Any idea what else I could do? :(

Newbie

Posts

Joined
Tue Dec 01, 2020 4:34 pm

Post by ADD Creative » Tue Dec 15, 2020 12:47 am

raph7 wrote:
Mon Dec 14, 2020 11:50 pm
I did all the steps mentioned on this topic.. But it is still duplicating for me... Any idea what else I could do? :(
Have you refreshed your modifications and checked that the changes made are applied any files that exist in storage/modification?

You could also try a slightly different version of the workaround.
https://github.com/ADDCreative/opencart ... 7b357a7ce2

www.add-creative.co.uk


Active Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by raph7 » Tue Dec 15, 2020 4:36 pm

ADD Creative wrote:
Tue Dec 15, 2020 12:47 am
raph7 wrote:
Mon Dec 14, 2020 11:50 pm
I did all the steps mentioned on this topic.. But it is still duplicating for me... Any idea what else I could do? :(
Have you refreshed your modifications and checked that the changes made are applied any files that exist in storage/modification?

You could also try a slightly different version of the workaround.
https://github.com/ADDCreative/opencart ... 7b357a7ce2


Do you mean to go into this path /system/storage/modification... and look for the following? If not, ignore what I put there untill --end--

under the paths:
/system/storage/modification/catalog/controller/account/login.php
/system/storage/modification/catalog/controller/account/register.php

- I do have the files login and register but both dont have any of the code that I added in the other files as mentioned in the post before...

under the path:
/system/storage/modification/catalog/controller/checkout
I only have these files: https://prnt.sc/w306aq
That means I dont have login.php and register.php

and under the path:
/system/storage/modification/system
I dont have a folder nor file called cart...

--end--

Another question is...
Should I add this 'workaround' https://github.com/ADDCreative/opencart ... 7b357a7ce2
that you gave me with those changes I already did or should I go back to how it was and then do this work around?

Thank you

Newbie

Posts

Joined
Tue Dec 01, 2020 4:34 pm

Post by ADD Creative » Tue Dec 15, 2020 7:30 pm

raph7 wrote:
Tue Dec 15, 2020 4:36 pm
Do you mean to go into this path /system/storage/modification... and look for the following? If not, ignore what I put there untill --end--

under the paths:
/system/storage/modification/catalog/controller/account/login.php
/system/storage/modification/catalog/controller/account/register.php

- I do have the files login and register but both dont have any of the code that I added in the other files as mentioned in the post before...

under the path:
/system/storage/modification/catalog/controller/checkout
I only have these files: https://prnt.sc/w306aq
That means I dont have login.php and register.php

and under the path:
/system/storage/modification/system
I dont have a folder nor file called cart...

--end--

Another question is...
Should I add this 'workaround' https://github.com/ADDCreative/opencart ... 7b357a7ce2
that you gave me with those changes I already did or should I go back to how it was and then do this work around?

Thank you
If you don't have any extension that modify those files then you won't find them in storage/modification. If the two files in storage/modification/catalog/controller/account don't have your changes, try refreshing your modifications. In admin go to Extension -> Modifications, then click the blue refresh button in the top right corner.

If you wanted to try the other workaround then you would need to undo the changes you have already made first.

www.add-creative.co.uk


Active Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by raph7 » Tue Dec 15, 2020 8:21 pm

ADD Creative wrote:
Tue Dec 15, 2020 7:30 pm
raph7 wrote:
Tue Dec 15, 2020 4:36 pm
Do you mean to go into this path /system/storage/modification... and look for the following? If not, ignore what I put there untill --end--

under the paths:
/system/storage/modification/catalog/controller/account/login.php
/system/storage/modification/catalog/controller/account/register.php

- I do have the files login and register but both dont have any of the code that I added in the other files as mentioned in the post before...

under the path:
/system/storage/modification/catalog/controller/checkout
I only have these files: https://prnt.sc/w306aq
That means I dont have login.php and register.php

and under the path:
/system/storage/modification/system
I dont have a folder nor file called cart...

--end--

Another question is...
Should I add this 'workaround' https://github.com/ADDCreative/opencart ... 7b357a7ce2
that you gave me with those changes I already did or should I go back to how it was and then do this work around?

Thank you
If you don't have any extension that modify those files then you won't find them in storage/modification. If the two files in storage/modification/catalog/controller/account don't have your changes, try refreshing your modifications. In admin go to Extension -> Modifications, then click the blue refresh button in the top right corner.

If you wanted to try the other workaround then you would need to undo the changes you have already made first.
Yeah I just realised I was looking into a different storage... (the one inside my website files and not the one outside)... I found the code there in the 2 files.. What should I do now?

Newbie

Posts

Joined
Tue Dec 01, 2020 4:34 pm

Post by ADD Creative » Tue Dec 15, 2020 9:00 pm

raph7 wrote:
Tue Dec 15, 2020 8:21 pm
Yeah I just realised I was looking into a different storage... (the one inside my website files and not the one outside)... I found the code there in the 2 files.. What should I do now?
If you are sure you have made all the changes and that any files that exist in storage/modification also have the changes, then either there is some sort of mistake with the changes you have made or your issue is caused by something else.

www.add-creative.co.uk


Active Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom
Who is online

Users browsing this forum: No registered users and 6 guests