Jump to content

context->customer->id is null


Presta Web Developer

Recommended Posts

Hi,

I have a problem for some customers.
When someone buy a product, they should go to the order confirmation site. The correct flow:
1. 4 step ptestashop checkout
2. Redirected to external payment gateway (in this step the customer leaves my site, to make payment)
3. Order confirmation page

In step 3, some customers, get an 302 on the Order confirmation site, and is redirected to history.

I have debug the code and can see the redirct happening in /PRESTASHOPPATH/controller/front/OrderConfirmationController.php, init function:

    public function init()
    {
        parent::init();

        if (true === (bool) Tools::getValue('free_order')) {
            $this->checkFreeOrder();
        }

        $this->id_cart = (int) (Tools::getValue('id_cart', 0));

        $redirectLink = 'index.php?controller=history';

        $this->id_module = (int) (Tools::getValue('id_module', 0));
        $this->id_order = Order::getIdByCartId((int) ($this->id_cart));
        $this->secure_key = Tools::getValue('key', false);
        $order = new Order((int) ($this->id_order));

        if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key)) {
            Tools::redirect($redirectLink . (Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
        }
        $this->reference = $order->reference;
        if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) {
            Tools::redirect($redirectLink);
        }
        $module = Module::getInstanceById((int) ($this->id_module));
        if ($order->module != $module->name) {
            Tools::redirect($redirectLink);
        }
        $this->order_presenter = new OrderPresenter();
    }

I have found out the problem is in the variable: $this->context->customer->id, which is null on the customers who is redirected

I can't replicate the error myself.

I'm running Prestashop 1.7.7.5.

Does someone have an idea why? how is the context->customer object initialized, and why should it be deleted on some customers?

Link to comment
Share on other sites

  • 3 weeks later...
On 11/14/2021 at 2:57 PM, musicmaster said:

My guess would be that it prepares the Customer id for being saved in the ps_orders table with the order record for this order.

Thanks for the reply.

I have just checked the id_customer field in the ps_orders table and all off them are fullfilled. so I don't think thats the reason.

Link to comment
Share on other sites

  • 1 month later...

Hey,

I have exactly the same problem with PS 1.7.8.2. I am doing a redirect after the successful order update from my ModuleFrontController to ...index.php?controller=order-confirmation. 

In my ModuleFrontCOntroller the context customer is set but after the redirect somehow it gets deleted and in OrderConfirmationController.php it is null and hence the customer is not shown a successful payment page but instead order history.

Any ideas?

 

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...