Is it possible to restrict coupon code by chosen currency in OpenCart?
E.g.
Shop had two currency XX and YY. If buyer pick XX currency, Coupon code field is visible in Shopping Cart. In other case (currency YY chosen) not.
OpenCart 2.0.3.1
Yes, Open this file:
catalog/controller/checkout/coupon.php in version 2.0.3.1
find:
if (empty($this->request->post['coupon'])) {
$json['error'] = $this->language->get('error_empty');
unset($this->session->data['coupon']);
} elseif ($coupon_info) {
$this->session->data['coupon'] = $this->request->post['coupon'];
$this->session->data['success'] = $this->language->get('text_success');
$json['redirect'] = $this->url->link('checkout/cart');
} else {
$json['error'] = $this->language->get('error_coupon');
}
change it to:
if (empty($this->request->post['coupon'])) {
$json['error'] = $this->language->get('error_empty');
unset($this->session->data['coupon']);
} elseif ($coupon_info) {
// here I use USD for example
if($this->session->data['currency'] == 'USD'){
$this->session->data['coupon'] = $this->request->post['coupon'];
$this->session->data['success'] = $this->language->get('text_success');
$json['redirect'] = $this->url->link('checkout/cart');
} else {
// Write your custom error message here
$json['error'] = 'This coupon is only available in USD';
unset($this->session->data['coupon']);
}
} else {
$json['error'] = $this->language->get('error_coupon');
}
Related
How can I construct a URL that will automatically fill in a field on the target page?,
I tried already https://www.mywebsite.com/index.php?route=account/register?name=firstname to fill first name on registration form, but for opencart it won't work, so please tell me what I missing here?
Thank you.
In this file:
catalog\controller\account\register.php
Find:
if (isset($this->request->post['firstname'])) {
$data['firstname'] = $this->request->post['firstname'];
} else {
$data['firstname'] = '';
}
Change it to:
if (isset($this->request->post['firstname'])) {
$data['firstname'] = $this->request->post['firstname'];
} else if (isset($this->request->get['name'])) {
$data['firstname'] = $this->request->get['name'];
} else {
$data['firstname'] = '';
}
I need your help, now in Store settings prices with tax!
So it is okey.
But when customer logged in, i need it without tax only on product page and in category.
How can i do this?
Thank you!
Hello #Ivan go to the catalog/controller/product.php and in your public function index() search for the
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']); `
}else {
$data['price'] = false;
}
Change it to :
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$data['price'] = $this->currency->format($product_info['price'], $this->session->data['currency']);
}else {
$data['price'] = false;
}
I want show in category multiple curency price
i have a code tike this
$this->currency->convert($price, 'RUB', 'CNY'),
Where to put this in caregory controller for working?
I resolve my problem like this
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
$price_2 = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), 'CNY');
} else {
$price = false;
$price_2 = false;
}
Maybe someone have better way to make.
Below is add to product code . But I am not getting where the values are storing . Kindly help to find out solution for this . I want to know logic behind this code
public function add($product_id, $qty = 1, $option = array(), $recurring_id = 0) {
$this->data = array();
$product['product_id'] = (int)$product_id;
if ($option) {
$product['option'] = $option;
}
if ($recurring_id) {
$product['recurring_id'] = (int)$recurring_id;
}
$key = base64_encode(serialize($product));
if ((int)$qty && ((int)$qty > 0)) {
if (!isset($this->session->data['cart'][$key])) {
$this->session->data['cart'][$key] = (int)$qty;
} else {
$this->session->data['cart'][$key] += (int)$qty;
}
}
}
The product details with options are stored in $key = base64_encode(serialize($product));. Where $this->session->data['cart'][$key] contains the number of quantity added by the customer.
For more details check the getProducts() function on the same page. Where you can find
foreach ($this->session->data['cart'] as $key => $quantity) {
....
$product = unserialize(base64_decode($key));
....
}
Actually am trying to add a foreign key field in my form like how it happens in django admin site . When you click on the green " + " button it opens up a new pop up window where you add the respective field .
My models are like :
class DealType(models.Model):
label = models.CharField(max_length = 100)
def __unicode__(self):
return self.label
class Deal(models.Model):
label = models.ForeignKey(DealType, blank = True, null = True)
.
.
.
And i want to add DealType while i fill up my DealForm .
I think you have to create a seperate view to create a DealType.
In your DealForm you add a link to open that view.
...
I took a look at an admin page from a project of mine.
html
<img src="/static/admin/img/admin/icon_addlink.gif" width="10" height="10" alt="Add Another"/>
Javascript
taken from
<script type="text/javascript" src="/static/admin/js/admin/RelatedObjectLookups.js"> </script>
function showAddAnotherPopup(triggeringLink) {
var name = triggeringLink.id.replace(/^add_/, '');
name = id_to_windowname(name);
href = triggeringLink.href
if (href.indexOf('?') == -1) {
href += '?_popup=1';
} else {
href += '&_popup=1';
}
var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
win.focus();
return false;
}
This opens a new window with the view with the add form.
This view should add the DealType and then close the window using the following function also found in the same javascript file
function dismissAddAnotherPopup(win, newId, newRepr) {
// newId and newRepr are expected to have previously been escaped by
// django.utils.html.escape.
newId = html_unescape(newId);
newRepr = html_unescape(newRepr);
var name = windowname_to_id(win.name);
var elem = document.getElementById(name);
if (elem) {
if (elem.nodeName == 'SELECT') {
var o = new Option(newRepr, newId);
elem.options[elem.options.length] = o;
o.selected = true;
} else if (elem.nodeName == 'INPUT') {
if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
elem.value += ',' + newId;
} else {
elem.value = newId;
}
}
} else {
var toId = name + "_to";
elem = document.getElementById(toId);
var o = new Option(newRepr, newId);
SelectBox.add_to_cache(toId, o);
SelectBox.redisplay(toId);
}
win.close();
}
This is just backtracked from the admin panel but it should get you started.
...
Found a guide that walks you through the process here which probably explains alot better. (havn't read it)