'Open Cart 3 How to get sku of cart product
i am trying to build a extension where i want to get sku value of product on cart page, checkout page and product page. I have set the fields at backend where admin can set the company id which will be pass in button URL. how can i get the sku value on cart page. I tried many different methods but it dosent work. i am also trying to get it on product & checkout page. is there anyone who can help me out.
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<name>Fast Checkout</name>
<version>1.0</version>
<link>https://google.com</link>
<author>Jamil Baig</author>
<code>fast_checkout</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: 'https://adup.iot',
dataType: 'json',
success: function(json) {
$('#cart-total').html(json['total']);
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
location = 'https://adup.io';
} else {
$('#cart > ul').load('https://adup.io ul li');
}
}
});
}
</script>
<a style="cursor:pointer;"><strong><i class="fa fa-times"></i> {{button_fastcheckout }}</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_fastcheckout'] = $this->language->get('button_fastcheckout');]]></add>
</operation>
</file>
<file path="catalog/controller/checkout/cart.php">
<operation>
<search><![CDATA[$this->load->language('checkout/cart');]]></search>
<add position="after"><![CDATA[$this->load->controller("admin/controller/extension/module/fastcheckout");
$this->load->model('catalog/product');
$data['button_fastcheckout'] = $this->language->get('Fast Checkout');
$products = $this->cart->getProducts();
foreach ($products as $product) {
$data['product_id'] = $product['product_id'];
}
$data['link_button'] = 'https://adup.io/?companyid='.$this->config->get('module_fastcheckout_company_id').'&sku='.$data['product_id'].'&p_id='.$data['product_id'];]]></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_fastcheckout'] = '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_fastcheckout'] = '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_button }}" class="btn btn-default" title="{{button_fastcheckout}}">{{button_fastcheckout}}</a>]]></add>
</operation>
</file>
</modification>
Solution 1:[1]
solved
after getting product id, i can get sku of product on cart page
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Muhammad Jamil Baig |
