ミニカートにボタンを追加して、クリックするとカート内のすべての商品をクリアします。 私は返事なしやや似た質問が見つかりました: How to clear cart after logout in opencart 2.x?opencartでカートをクリアするボタンを追加するには?
がOpenCart 3.0にこの機能を追加することが可能ですか?
おかげ
ミニカートにボタンを追加して、クリックするとカート内のすべての商品をクリアします。 私は返事なしやや似た質問が見つかりました: How to clear cart after logout in opencart 2.x?opencartでカートをクリアするボタンを追加するには?
がOpenCart 3.0にこの機能を追加することが可能ですか?
おかげ
あなたは、Ajaxリクエストを通じてカートライブラリでclear
メソッドを使用することができます。
このファイルを編集:
catalog\controller\checkout\cart.php
検索:
public function remove() {
その前に追加します。
public function clear() {
$this->load->language('checkout/cart');
$json = array();
$this->cart->clear();
unset($this->session->data['vouchers']);
$json['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']);
$json['total'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format(0, $this->session->data['currency']));
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
このファイルを編集(デフォルトのテーマを使用していると仮定します):
catalog\view\javascript\common.js
検索:
'remove': function(key) {
をその前に追加します。
'clear': function() {
$.ajax({
url: 'index.php?route=checkout/cart/clear',
type: 'post',
data: '',
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
complete: function() {
$('#cart > button').button('reset');
},
success: function(json) {
// Need to set timeout otherwise it wont update the total
setTimeout(function() {
$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
}, 100);
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
location = 'index.php?route=checkout/cart';
} else {
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
},
そして最後にcart.twigを編集したり、どこかにこのボタンを表示する:
catalog\view\theme\default\template\common\cart.twig
追加:
<button class="btn btn-danger" onclick="cart.clear()"><i class="fa fa-trash"></i> Clear</button>
その後、すべてのキャッシュをクリアします。
を添付しました。彼はコメントから彼の答えを得たので、それは未回答です。あなたのケースでご確認ください –
こんにちは、ありがとうございます、しかし、私はログアウトではなくボタンを介してそれを達成したいと思います。 – Arthur