添加产品并转移到opencart中的结帐或购物车后,购物车变空

时间:2014-08-04 09:09:55

标签: opencart

我有一个非常奇怪的问题。当我将产品添加到顶部标题上的购物车时,它会显示购物车详细信息/产品。但是当我点击购物车或结账时,我说我的购物车是空的。因此,每次我添加产品并转移到结帐或购物车时,它都会自动变空。

我在firefox,chrome和不同的PC上试过这个网站,但仍然存在同样的问题。但奇怪的是,当我运行firebug并移动到控制台查看呼叫时,该网站运行良好。但当我关闭萤火虫并刷新页面或移动时,购物车再次变空。

有人可以告诉我这可能是什么问题吗?

我正在使用Opencart 1.5.4

结帐控制器功能

public function index() {
    // Validate cart has products and has stock.
    if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
        $this->redirect($this->url->link('checkout/cart'));
    }   

// Validate minimum quantity requirments.           
$products = $this->cart->getProducts();

foreach ($products as $product) {
    $product_total = 0;

    foreach ($products as $product_2) {
        if ($product_2['product_id'] == $product['product_id']) {
            $product_total += $product_2['quantity'];
        }
    }       

    if ($product['minimum'] > $product_total) {
        $this->redirect($this->url->link('checkout/cart'));
    }               
}

$this->language->load('checkout/checkout');

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

$this->data['breadcrumbs'] = array();

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

$this->data['breadcrumbs'][] = array(
    'text'      => $this->language->get('text_cart'),
    'href'      => $this->url->link('checkout/cart'),
    'separator' => $this->language->get('text_separator')
);

$this->data['breadcrumbs'][] = array(
    'text'      => $this->language->get('heading_title'),
    'href'      => $this->url->link('checkout/checkout', '', 'SSL'),
    'separator' => $this->language->get('text_separator')
);

$this->data['heading_title'] = $this->language->get('heading_title');

$this->data['text_checkout_option'] = $this->language->get('text_checkout_option');
$this->data['text_checkout_account'] = $this->language->get('text_checkout_account');
$this->data['text_checkout_payment_address'] = $this->language->get('text_checkout_payment_address');
$this->data['text_checkout_shipping_address'] = $this->language->get('text_checkout_shipping_address');
$this->data['text_checkout_shipping_method'] = $this->language->get('text_checkout_shipping_method');
$this->data['text_checkout_payment_method'] = $this->language->get('text_checkout_payment_method');     
$this->data['text_checkout_confirm'] = $this->language->get('text_checkout_confirm');
$this->data['text_modify'] = $this->language->get('text_modify');

$this->data['logged'] = $this->customer->isLogged();
$this->data['shipping_required'] = $this->cart->hasShipping();  

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/checkout.tpl')) {
    $this->template = $this->config->get('config_template') . '/template/checkout/checkout.tpl';
} else {
    $this->template = 'default/template/checkout/checkout.tpl';
}

$this->children = array(
    'common/column_left',
    'common/column_right',
    'common/content_top',
    'common/content_bottom',
    'common/footer',
    'common/header' 
);

$this->response->setOutput($this->render());
}

购物车控制器

public function index() {
$this->language->load('checkout/cart');

if (!isset($this->session->data['vouchers'])) {
    $this->session->data['vouchers'] = array();
}

// Update
if (!empty($this->request->post['quantity'])) {
    foreach ($this->request->post['quantity'] as $key => $value) {
        $this->cart->update($key, $value);
    }

    unset($this->session->data['shipping_method']);
    unset($this->session->data['shipping_methods']);
    unset($this->session->data['payment_method']);
    unset($this->session->data['payment_methods']); 
    unset($this->session->data['reward']);

    $this->redirect($this->url->link('checkout/cart'));             
}

// Remove
if (isset($this->request->get['remove'])) {
    $this->cart->remove($this->request->get['remove']);

    unset($this->session->data['vouchers'][$this->request->get['remove']]);

    $this->session->data['success'] = $this->language->get('text_remove');

    unset($this->session->data['shipping_method']);
    unset($this->session->data['shipping_methods']);
    unset($this->session->data['payment_method']);
    unset($this->session->data['payment_methods']); 
    unset($this->session->data['reward']);  

    $this->redirect($this->url->link('checkout/cart'));
}

// Coupon    
if (isset($this->request->post['coupon']) && $this->validateCoupon()) { 
    $this->session->data['coupon'] = $this->request->post['coupon'];

    $this->session->data['success'] = $this->language->get('text_coupon');

    $this->redirect($this->url->link('checkout/cart'));
}

// Voucher
if (isset($this->request->post['voucher']) && $this->validateVoucher()) { 
    $this->session->data['voucher'] = $this->request->post['voucher'];

    $this->session->data['success'] = $this->language->get('text_voucher');

    $this->redirect($this->url->link('checkout/cart'));
}

// Reward
if (isset($this->request->post['reward']) && $this->validateReward()) { 
    $this->session->data['reward'] = abs($this->request->post['reward']);

    $this->session->data['success'] = $this->language->get('text_reward');

    $this->redirect($this->url->link('checkout/cart'));
}

// Shipping
if (isset($this->request->post['shipping_method']) && $this->validateShipping()) {
    $shipping = explode('.', $this->request->post['shipping_method']);

    $this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];

    $this->session->data['success'] = $this->language->get('text_shipping');

    $this->redirect($this->url->link('checkout/cart'));
}

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

$this->data['breadcrumbs'] = array();

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

$this->data['breadcrumbs'][] = array(
    'href'      => $this->url->link('checkout/cart'),
    'text'      => $this->language->get('heading_title'),
    'separator' => $this->language->get('text_separator')
);

if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) {
    $points = $this->customer->getRewardPoints();

    $points_total = 0;

    foreach ($this->cart->getProducts() as $product) {
        if ($product['points']) {
            $points_total += $product['points'];
        }
    }       

    $this->data['heading_title'] = $this->language->get('heading_title');

    $this->data['text_next'] = $this->language->get('text_next');
    $this->data['text_next_choice'] = $this->language->get('text_next_choice');
    $this->data['text_use_coupon'] = $this->language->get('text_use_coupon');
    $this->data['text_use_voucher'] = $this->language->get('text_use_voucher');
    $this->data['text_use_reward'] = sprintf($this->language->get('text_use_reward'), $points);
    $this->data['text_shipping_estimate'] = $this->language->get('text_shipping_estimate');
    $this->data['text_shipping_detail'] = $this->language->get('text_shipping_detail');
    $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
    $this->data['text_select'] = $this->language->get('text_select');
    $this->data['text_none'] = $this->language->get('text_none');

    $this->data['column_image'] = $this->language->get('column_image');
    $this->data['column_name'] = $this->language->get('column_name');
    $this->data['column_model'] = $this->language->get('column_model');
    $this->data['column_quantity'] = $this->language->get('column_quantity');
    $this->data['column_price'] = $this->language->get('column_price');
    $this->data['column_total'] = $this->language->get('column_total');

    $this->data['entry_coupon'] = $this->language->get('entry_coupon');
    $this->data['entry_voucher'] = $this->language->get('entry_voucher');
    $this->data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total);
    $this->data['entry_country'] = $this->language->get('entry_country');
    $this->data['entry_zone'] = $this->language->get('entry_zone');
    $this->data['entry_postcode'] = $this->language->get('entry_postcode');

    $this->data['button_update'] = $this->language->get('button_update');
    $this->data['button_remove'] = $this->language->get('button_remove');
    $this->data['button_coupon'] = $this->language->get('button_coupon');
    $this->data['button_voucher'] = $this->language->get('button_voucher');
    $this->data['button_reward'] = $this->language->get('button_reward');
    $this->data['button_quote'] = $this->language->get('button_quote');
    $this->data['button_shipping'] = $this->language->get('button_shipping');           
    $this->data['button_shopping'] = $this->language->get('button_shopping');
    $this->data['button_checkout'] = $this->language->get('button_checkout');

    if (isset($this->error['warning'])) {
        $this->data['error_warning'] = $this->error['warning'];
    } elseif (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) {
        $this->data['error_warning'] = $this->language->get('error_stock');     
    } else {
        $this->data['error_warning'] = '';
    }

    if ($this->config->get('config_customer_price') && !$this->customer->isLogged()) {
        $this->data['attention'] = sprintf($this->language->get('text_login'), $this->url->link('account/login'), $this->url->link('account/register'));
    } else {
        $this->data['attention'] = '';
    }

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

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

    $this->data['action'] = $this->url->link('checkout/cart');   

    if ($this->config->get('config_cart_weight')) {
        $this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point'));
    } else {
        $this->data['weight'] = '';
    }

    $this->load->model('tool/image');

    $this->data['products'] = array();

    $products = $this->cart->getProducts();

    foreach ($products as $product) {
        $product_total = 0;

        foreach ($products as $product_2) {
            if ($product_2['product_id'] == $product['product_id']) {
                $product_total += $product_2['quantity'];
            }
        }           

        if ($product['minimum'] > $product_total) {
            $this->data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']);
        }               

        if ($product['image']) {
            $image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
        } else {
            $image = '';
        }

        $option_data = array();

        foreach ($product['option'] as $option) {
            if ($option['type'] != 'file') {
                $value = $option['option_value'];   
            } else {
                $filename = $this->encryption->decrypt($option['option_value']);

                $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.'));
            }

            $option_data[] = array(
                'name'  => $option['name'],
                'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
            );
        }

        // Display prices
        if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
            $price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')));
        } else {
            $price = false;
        }

        // Display prices
        if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
            $total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']);
        } else {
            $total = false;
        }

        $this->data['products'][] = array(
            'key'      => $product['key'],
            'thumb'    => $image,
            'name'     => $product['name'],
            'model'    => $product['model'],
            'option'   => $option_data,
            'quantity' => $product['quantity'],
            'stock'    => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')),
            'reward'   => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
            'price'    => $price,
            'total'    => $total,
            'href'     => $this->url->link('product/product', 'product_id=' . $product['product_id']),
            'remove'   => $this->url->link('checkout/cart', 'remove=' . $product['key'])
        );
    }

    // Gift Voucher
    $this->data['vouchers'] = array();

    if (!empty($this->session->data['vouchers'])) {
        foreach ($this->session->data['vouchers'] as $key => $voucher) {
            $this->data['vouchers'][] = array(
                'key'         => $key,
                'description' => $voucher['description'],
                'amount'      => $this->currency->format($voucher['amount']),
                'remove'      => $this->url->link('checkout/cart', 'remove=' . $key)   
            );
        }
    }

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

    $this->data['coupon_status'] = $this->config->get('coupon_status');

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

    $this->data['voucher_status'] = $this->config->get('voucher_status');

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

    $this->data['reward_status'] = ($points && $points_total && $this->config->get('reward_status'));

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

    $this->data['shipping_status'] = $this->config->get('shipping_status') && $this->config->get('shipping_estimator') && $this->cart->hasShipping();   

    if (isset($this->request->post['country_id'])) {
        $this->data['country_id'] = $this->request->post['country_id'];             
    } elseif (isset($this->session->data['shipping_country_id'])) {
        $this->data['country_id'] = $this->session->data['shipping_country_id'];                
    } else {
        $this->data['country_id'] = $this->config->get('config_country_id');
    }

    $this->load->model('localisation/country');

    $this->data['countries'] = $this->model_localisation_country->getCountries();

    if (isset($this->request->post['zone_id'])) {
        $this->data['zone_id'] = $this->request->post['zone_id'];               
    } elseif (isset($this->session->data['shipping_zone_id'])) {
        $this->data['zone_id'] = $this->session->data['shipping_zone_id'];          
    } else {
        $this->data['zone_id'] = '';
    }

    if (isset($this->request->post['postcode'])) {
        $this->data['postcode'] = $this->request->post['postcode'];             
    } elseif (isset($this->session->data['shipping_postcode'])) {
        $this->data['postcode'] = $this->session->data['shipping_postcode'];                    
    } else {
        $this->data['postcode'] = '';
    }

    if (isset($this->request->post['shipping_method'])) {
        $this->data['shipping_method'] = $this->request->post['shipping_method'];               
    } elseif (isset($this->session->data['shipping_method'])) {
        $this->data['shipping_method'] = $this->session->data['shipping_method']['code']; 
    } else {
        $this->data['shipping_method'] = '';
    }

    // Totals
    $this->load->model('setting/extension');

    $total_data = array();                  
    $total = 0;
    $taxes = $this->cart->getTaxes();

    // Display prices
    if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
        $sort_order = array(); 

        $results = $this->model_setting_extension->getExtensions('total');

        foreach ($results as $key => $value) {
            $sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
        }

        array_multisort($sort_order, SORT_ASC, $results);

        foreach ($results as $result) {
            if ($this->config->get($result['code'] . '_status')) {
                $this->load->model('total/' . $result['code']);

                $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
            }

            $sort_order = array(); 

            foreach ($total_data as $key => $value) {
                $sort_order[$key] = $value['sort_order'];
            }

            array_multisort($sort_order, SORT_ASC, $total_data);            
        }
    }

    $this->data['totals'] = $total_data;

    $this->data['continue'] = $this->url->link('common/home');

    $this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/cart.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/checkout/cart.tpl';
    } else {
        $this->template = 'default/template/checkout/cart.tpl';
    }

    $this->children = array(
        'common/column_left',
        'common/column_right',
        'common/content_bottom',
        'common/content_top',
        'common/footer',
        'common/header' 
    );

    $this->response->setOutput($this->render());                    
} else {
    $this->data['heading_title'] = $this->language->get('heading_title');

    $this->data['text_error'] = $this->language->get('text_empty');

    $this->data['button_continue'] = $this->language->get('button_continue');

    $this->data['continue'] = $this->url->link('common/home');

    unset($this->session->data['success']);

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
    } else {
        $this->template = 'default/template/error/not_found.tpl';
    }

    $this->children = array(
        'common/column_left',
        'common/column_right',
        'common/content_top',
        'common/content_bottom',
        'common/footer',
        'common/header' 
    );

    $this->response->setOutput($this->render());            
    }
}

会话库

class Session {
    public $data = array();

    public function __construct() {     
        if (!session_id()) {
            ini_set('session.use_cookies', 'On');
            ini_set('session.use_trans_sid', 'Off');

            session_set_cookie_params(0, '/');
            session_start();
        }

        $this->data =& $_SESSION;
    }

        function getId() {
        return session_id();
    }
}

1 个答案:

答案 0 :(得分:0)

很难说,问题的根源在哪里。如果您有任何第三方扩展(VQMods),他们可以更改原始OpenCart代码。在这种情况下,您应该查看缓存文件,而不是原始文件。这是一个开始。