Jump to content

Is it possible to create a link to order detail?


liyinan

Recommended Posts

There is a form to track the orders placed as guest checkout, you can use this feature to achieve what you need, the link is (when friendly URL is enabled):

http://my-shop.com/en/guest-tracking?id_order=ORDERREFERENCEHERE&[email protected]

Obviously you will need replace...

ORDERREFERENCEHERE: With the order reference

[email protected]: With the customer email

 

Now you will need do a little change in the controller GuestTrackingController, because this feature is valid only for orders placed as guest checkout, as I said before, locate the file at:

/controllers/front/GuestTrackingController.php

Replace this code:

/**
* Start forms process
* @see FrontController::postProcess()
*/
public function postProcess()
{
    if (Tools::isSubmit('submitGuestTracking') || Tools::isSubmit('submitTransformGuestToCustomer')) {
        // These lines are here for retrocompatibility with old theme
        $id_order = Tools::getValue('id_order');
        $order_collection = array();
        if ($id_order) {
            if (is_numeric($id_order)) {
                $order = new Order((int)$id_order);
                if (Validate::isLoadedObject($order)) {
                    $order_collection = Order::getByReference($order->reference);
                }
            } else {
                $order_collection = Order::getByReference($id_order);
            }
        }
        // Get order reference, ignore package reference (after the #, on the order reference)
        $order_reference = current(explode('#', Tools::getValue('order_reference')));
        // Ignore $result_number
        if (!empty($order_reference)) {
            $order_collection = Order::getByReference($order_reference);
        }

        $email = Tools::getValue('email');

        if (empty($order_reference) && empty($id_order)) {
            $this->errors[] = Tools::displayError('Please provide your order\'s reference number.');
        } elseif (empty($email)) {
            $this->errors[] = Tools::displayError('Please provide a valid email address.');
        } elseif (!Validate::isEmail($email)) {
            $this->errors[] = Tools::displayError('Please provide a valid email address.');
        } elseif (!Customer::customerExists($email, false, false)) {
            $this->errors[] = Tools::displayError('There is no account associated with this email address.');
        } elseif (Customer::customerExists($email, false, true)) {
            $this->errors[] = Tools::displayError('This page is for guest accounts only. Since your guest account has already been transformed into a customer account, you can no longer view your order here. Please log in to your customer account to view this order');
            $this->context->smarty->assign('show_login_link', true);
        } elseif (!count($order_collection)) {
            $this->errors[] = Tools::displayError('Invalid order reference');
        } elseif (!$order_collection->getFirst()->isAssociatedAtGuest($email)) {
            $this->errors[] = Tools::displayError('Invalid order reference');
        } else {
            $this->assignOrderTracking($order_collection);
            if (Tools::isSubmit('submitTransformGuestToCustomer')) {
                $customer = new Customer((int)$order->id_customer);
                if (!Validate::isLoadedObject($customer)) {
                    $this->errors[] = Tools::displayError('Invalid customer');
                } elseif (!Tools::getValue('password')) {
                    $this->errors[] = Tools::displayError('Invalid password.');
                } elseif (!$customer->transformToCustomer($this->context->language->id, Tools::getValue('password'))) {
                    // @todo clarify error message
                    $this->errors[] = Tools::displayError('An error occurred while transforming a guest into a registered customer.');
                } else {
                    $this->context->smarty->assign('transformSuccess', true);
                }
            }
        }
    }
}

For this:

/**
* Start forms process
* @see FrontController::postProcess()
*/
public function postProcess()
{
    if (Tools::isSubmit('submitGuestTracking') || Tools::isSubmit('submitTransformGuestToCustomer')) {
        // These lines are here for retrocompatibility with old theme
        $id_order = Tools::getValue('id_order');
        $order_collection = array();
        if ($id_order) {
            if (is_numeric($id_order)) {
                $order = new Order((int)$id_order);
                if (Validate::isLoadedObject($order)) {
                    $order_collection = Order::getByReference($order->reference);
                }
            } else {
                $order_collection = Order::getByReference($id_order);
            }
        }

        // Get order reference, ignore package reference (after the #, on the order reference)
        $order_reference = current(explode('#', Tools::getValue('order_reference')));
        // Ignore $result_number
        if (!empty($order_reference)) {
            $order_collection = Order::getByReference($order_reference);
        }
        $email = Tools::getValue('email');
        if (empty($order_reference) && empty($id_order)) {
            $this->errors[] = Tools::displayError('Please provide your order\'s reference number.');
        } elseif (empty($email)) {
            $this->errors[] = Tools::displayError('Please provide a valid email address.');
        } elseif (!Validate::isEmail($email)) {
            $this->errors[] = Tools::displayError('Please provide a valid email address.');
        } elseif (!Customer::customerExists($email, false, false)) {
            $this->errors[] = Tools::displayError('There is no account associated with this email address.');
        } /*elseif (Customer::customerExists($email, false, true)) {
            $this->errors[] = Tools::displayError('This page is for guest accounts only. Since your guest account has already been transformed into a customer account, you can no longer view your order here. Please log in to your customer account to view this order');
            $this->context->smarty->assign('show_login_link', true);
        }*/ elseif (!count($order_collection)) {
            $this->errors[] = Tools::displayError('Invalid order reference');
        } /*elseif (!$order_collection->getFirst()->isAssociatedAtGuest($email)) {
            $this->errors[] = Tools::displayError('Invalid order reference');
        }*/ else {
            $this->assignOrderTracking($order_collection);
            if (Tools::isSubmit('submitTransformGuestToCustomer')) {
                $customer = new Customer((int)$order->id_customer);
                if (!Validate::isLoadedObject($customer)) {
                    $this->errors[] = Tools::displayError('Invalid customer');
                } elseif (!Tools::getValue('password')) {
                    $this->errors[] = Tools::displayError('Invalid password.');
                } elseif (!$customer->transformToCustomer($this->context->language->id, Tools::getValue('password'))) {
                    // @todo clarify error message
                    $this->errors[] = Tools::displayError('An error occurred while transforming a guest into a registered customer.');
                } else {
                    $this->context->smarty->assign('transformSuccess', true);
                }
            }
        }
    }
}
  • Like 1
Link to comment
Share on other sites

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...