Issue
I am creating an extention to add custom button on Product & Cart page. I have created a extension through which i can set fields, now i want to display the button on those pages. I try one sample code but it is not working, i don't understand where to place that file. here is the code:
`
<name>ClearShoppingCart by iSenseLabs</name>
<version>1.0 (Initial)</version>
<link>https://isenselabs.com</link>
<author>iSenseLabs</author>
<code>isenselabs_clearshoppingcart</code>
<file path="catalog/view/theme/*/template/common/cart.twig">
<operation>
<search><![CDATA[<a href="{{ cart }}"><strong><i class="fa fa-shopping-cart"></i>]]></search>
<add position="replace"><![CDATA[
<script type="text/javascript">
function clearCart() {
$.ajax({
url: 'index.php?route=checkout/cart/clearcart',
dataType: 'json',
success: function(json) {
$('#cart-total').html(json['total']);
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');
}
}
});
}
</script>
<a style="cursor:pointer;" onclick="clearCart();" ><strong><i class="fa fa-times"></i> {{button_clearcart }}</strong></a> <a href="{{ cart }}"><strong><i class="fa fa-shopping-cart"></i>
]]></add>
</operation>
</file>
<file path="catalog/controller/checkout/cart.php">
<operation>
<search><![CDATA[public function add() {]]></search>
<add position="before"><![CDATA[
public function clearcart() {
$this->load->language('checkout/cart');
$json = array();
$this->cart->clear();
$total = 0;
unset($this->session->data['vouchers']);
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($total, $this->config->get('config_currency')));
if (isset($this->request->get['shoppingcart']) && $this->request->get['shoppingcart']=='true') {
$this->response->redirect($this->url->link('checkout/cart'));
} else {
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
]]></add>
</operation>
</file>
<file path="catalog/controller/common/cart.php">
<operation>
<search><![CDATA[$this->load->language('common/cart');]]></search>
<add position="after"><![CDATA[
$data['button_clearcart'] = $this->language->get('button_clearcart');
]]></add>
</operation>
</file>
<file path="catalog/controller/checkout/cart.php">
<operation>
<search><![CDATA[$this->load->language('checkout/cart');]]></search>
<add position="after"><![CDATA[
$data['button_clearcart'] = $this->language->get('button_clearcart');
$data['link_clearcart'] = $this->url->link('checkout/cart/clearcart', 'shoppingcart=true');
]]></add>
</operation>
</file>
<file path="catalog/language/en-gb/common/cart.php">
<operation>
<search><![CDATA[$_['text_recurring'] = 'Payment Profile';]]></search>
<add position="before"><![CDATA[
$_['button_clearcart'] = 'Clear Cart';
]]></add>
</operation>
</file>
<file path="catalog/language/en-gb/checkout/cart.php">
<operation>
<search><![CDATA[$_['column_total'] = 'Total';]]></search>
<add position="before"><![CDATA[
$_['button_clearcart'] = 'Clear Cart';
]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/checkout/cart.twig">
<operation>
<search><![CDATA[{% if modules %}]]></search>
<add position="before"><![CDATA[
<a href="{{ link_clearcart }}" class="btn btn-default" title="{{button_clearcart}}">{{button_clearcart}}</a>
]]></add>
</operation>
</file>
`
i am saving it with install.xml and make it zip. it installed successfully but nothing comes up.
Solution
Try to add to your xml something like this:
<file path="catalog/view/theme/*/template/product/product.twig">
<operation>
<search><![CDATA[<button type="button" id="button-cart" data-loading-text="{{ text_loading }}" class="btn btn-primary btn-lg btn-block">{{ button_cart }}</button>]]></search>
<add position="after"><![CDATA[
<a href="{{ link_clearcart }}" class="btn btn-default" title="{{button_clearcart}}">{{button_clearcart}}</a>
]]></add>
</operation>
</file>
Answered By - K. B. Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.