Próbuję wdrożyć funkcję, w której gość dodaje produkt do koszyka, po zalogowaniu się w HE / ona powinna zostać przekierowana na stronę kasy.

Jeśli koszyk jest pusty, użytkownik powinien zostać przekierowany na stronę z informacjami o swoim koncie (jest to warunek domyślny).

Wypróbowałem następujący warunek w tym pliku:

katalog/kontroler/konto/login.php

if ($this->customer->isLogged() && $this->cart->hasProducts()) { $this->response->redirect($this->url->link('checkout/cart', '', true)); } else { $this->response->redirect($this->url->link('account/account', '', true)); }

Problemem jest teraz, gdy pracuje, gdy loguję się z istniejącym kontem, który ma już produkt dodany do koszyka, ale nie działa, jeśli dodam produkt jako gość i po zalogowaniu się, a po zalogowaniu się wciąż jest przekierowany do strony informacji o koncie .

Jeśli moje wyjaśnienie nie jest jasne, daj mi znać, każda pomoc byłaby naprawdę wdzięczna!

EDYTOWAĆ:

Oto rejestrowanie ekranu tego problemu https://vimeo.com/307006071

Oto mój kod aktualizacji:

if ($this->customer->isLogged()) {
    $this->response->redirect($this->url->link('account/account', '', true));
}

$this->load->language('account/login');

$this->document->setTitle($this->language->get('heading_title'));

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
    // Unset guest
    unset($this->session->data['guest']);

    // Default Shipping Address
    $this->load->model('account/address');

    if ($this->config->get('config_tax_customer') == 'payment') {
        $this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
    }

    if ($this->config->get('config_tax_customer') == 'shipping') {
        $this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
    }

    // Wishlist
    if (isset($this->session->data['wishlist']) && is_array($this->session->data['wishlist'])) {
        $this->load->model('account/wishlist');

        foreach ($this->session->data['wishlist'] as $key => $product_id) {
            $this->model_account_wishlist->addWishlist($product_id);

            unset($this->session->data['wishlist'][$key]);
        }
    }

    // Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
    if (isset($this->request->post['redirect']) && $this->request->post['redirect'] != $this->url->link('account/logout', '', true) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
        $this->response->redirect(str_replace('&', '&', $this->request->post['redirect']));
    } else {
        if ($this->cart->hasProducts()) {
            $this->response->redirect($this->url->link('checkout/cart', '', true));
        }
        else {
            $this->response->redirect($this->url->link('account/account', '', true));
        }
    }
}
0
Kevin Abou Hanna 10 grudzień 2018, 13:22

1 odpowiedź

Najlepsza odpowiedź

Edytuj catalog/controller/account/login.php.

Okazuje się, że jeśli upoważnienie zakończyło się sukcesem, koszyk jest wyczyszczony. Zaktualizowałem rozwiązanie:

KOD AKTUALIZACJI:

<?php
class ControllerAccountLogin extends Controller {
    private $error = array();
    private $cartisempty = true; /* ADDING THIS */

    public function index() {
        $this->load->model('account/customer');

        // Login override for admin users
        if (!empty($this->request->get['token'])) {
            $this->customer->logout();
            $this->cart->clear();

            unset($this->session->data['order_id']);
            unset($this->session->data['payment_address']);
            unset($this->session->data['payment_method']);
            unset($this->session->data['payment_methods']);
            unset($this->session->data['shipping_address']);
            unset($this->session->data['shipping_method']);
            unset($this->session->data['shipping_methods']);
            unset($this->session->data['comment']);
            unset($this->session->data['coupon']);
            unset($this->session->data['reward']);
            unset($this->session->data['voucher']);
            unset($this->session->data['vouchers']);

            $customer_info = $this->model_account_customer->getCustomerByToken($this->request->get['token']);

            if ($customer_info && $this->customer->login($customer_info['email'], '', true)) {
                // Default Addresses
                $this->load->model('account/address');

                if ($this->config->get('config_tax_customer') == 'payment') {
                    $this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
                }

                if ($this->config->get('config_tax_customer') == 'shipping') {
                    $this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
                }

                $this->response->redirect($this->url->link('account/account', '', true));
            }
        }

        if ($this->customer->isLogged()) {
            $this->response->redirect($this->url->link('account/account', '', true));
        }

        $this->load->language('account/login');

        $this->document->setTitle($this->language->get('heading_title'));

        /* ADDING THIS - START */
        if( ($this->request->server['REQUEST_METHOD'] == 'POST') ){
            if( $this->cart->hasProducts() ){
                $this->cartisempty = false;
            }
        }
        /* ADDING THIS - END */

        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            // Unset guest
            unset($this->session->data['guest']);

            // Default Shipping Address
            $this->load->model('account/address');

            if ($this->config->get('config_tax_customer') == 'payment') {
                $this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
            }

            if ($this->config->get('config_tax_customer') == 'shipping') {
                $this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
            }

            // Wishlist
            if (isset($this->session->data['wishlist']) && is_array($this->session->data['wishlist'])) {
                $this->load->model('account/wishlist');

                foreach ($this->session->data['wishlist'] as $key => $product_id) {
                    $this->model_account_wishlist->addWishlist($product_id);

                    unset($this->session->data['wishlist'][$key]);
                }
            }

            // Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
            if (isset($this->request->post['redirect']) && $this->request->post['redirect'] != $this->url->link('account/logout', '', true) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
                $this->response->redirect(str_replace('&amp;', '&', $this->request->post['redirect']));
            } else {
                /* ADDING THIS - START */
                if( $this->cartisempty == false OR $this->cart->hasProducts() ){
                    $this->response->redirect($this->url->link('checkout/cart', '', true));
                } else {
                    $this->response->redirect($this->url->link('account/account', '', true));
                }
                /* ADDING THIS - END */
            }
        }

        $data['breadcrumbs'] = array();

        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/home')
        );

        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_account'),
            'href' => $this->url->link('account/account', '', true)
        );

        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_login'),
            'href' => $this->url->link('account/login', '', true)
        );

        if (isset($this->session->data['error'])) {
            $data['error_warning'] = $this->session->data['error'];

            unset($this->session->data['error']);
        } elseif (isset($this->error['warning'])) {
            $data['error_warning'] = $this->error['warning'];
        } else {
            $data['error_warning'] = '';
        }

        $data['action'] = $this->url->link('account/login', '', true);
        $data['register'] = $this->url->link('account/register', '', true);
        $data['forgotten'] = $this->url->link('account/forgotten', '', true);

        // Added strpos check to pass McAfee PCI compliance test (http://forum.opencart.com/viewtopic.php?f=10&t=12043&p=151494#p151295)
        if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], $this->config->get('config_url')) !== false || strpos($this->request->post['redirect'], $this->config->get('config_ssl')) !== false)) {
            $data['redirect'] = $this->request->post['redirect'];
        } elseif (isset($this->session->data['redirect'])) {
            $data['redirect'] = $this->session->data['redirect'];

            unset($this->session->data['redirect']);
        } else {
            $data['redirect'] = '';
        }

        if (isset($this->session->data['success'])) {
            $data['success'] = $this->session->data['success'];

            unset($this->session->data['success']);
        } else {
            $data['success'] = '';
        }

        if (isset($this->request->post['email'])) {
            $data['email'] = $this->request->post['email'];
        } else {
            $data['email'] = '';
        }

        if (isset($this->request->post['password'])) {
            $data['password'] = $this->request->post['password'];
        } else {
            $data['password'] = '';
        }

        $data['column_left'] = $this->load->controller('common/column_left');
        $data['column_right'] = $this->load->controller('common/column_right');
        $data['content_top'] = $this->load->controller('common/content_top');
        $data['content_bottom'] = $this->load->controller('common/content_bottom');
        $data['footer'] = $this->load->controller('common/footer');
        $data['header'] = $this->load->controller('common/header');

        $this->response->setOutput($this->load->view('account/login', $data));
    }

    protected function validate() {
        // Check how many login attempts have been made.
        $login_info = $this->model_account_customer->getLoginAttempts($this->request->post['email']);

        if ($login_info && ($login_info['total'] >= $this->config->get('config_login_attempts')) && strtotime('-1 hour') < strtotime($login_info['date_modified'])) {
            $this->error['warning'] = $this->language->get('error_attempts');
        }

        // Check if customer has been approved.
        $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']);

        if ($customer_info && !$customer_info['status']) {
            $this->error['warning'] = $this->language->get('error_approved');
        }

        if (!$this->error) {
            if (!$this->customer->login($this->request->post['email'], $this->request->post['password'])) {
                $this->error['warning'] = $this->language->get('error_login');

                $this->model_account_customer->addLoginAttempt($this->request->post['email']);
            } else {
                $this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
            }
        }

        return !$this->error;
    }
}
2
Alexander Semikashev 18 grudzień 2018, 14:26