我们如何通过Opencart 2.0.3中的代码检查购物车是否包含礼品券?
如果购物车有礼券(opencart 2.0.3),我想禁用货到付款(cod)支付模式。任何代码或想法来实现这一目标?
答案 0 :(得分:0)
是的,你可以这样做,在产品中你可以设置你的产品是否是礼品券的状态,之后有些情况会在订购时到达:
客户可以订购带有礼品券的产品,因此您必须检查是否有任何产品带有礼品券状态,而且不是COD
答案 1 :(得分:0)
如果存在礼券,您可以编辑cod.php模型(catalog / model / payment / cod.php)并添加条件。
你是说"代金券"使用"礼券和#34;
这是实际模型
<?php
class ModelPaymentCOD extends Model {
public function getMethod($address, $total) {
$this->load->language('payment/cod');
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('cod_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
if ($this->config->get('cod_total') > 0 && $this->config->get('cod_total') > $total) {
$status = false;
} elseif (!$this->config->get('cod_geo_zone_id')) {
$status = true;
} elseif ($query->num_rows) {
$status = true;
} else {
$status = false;
}
$method_data = array();
if ($status) {
$method_data = array(
'code' => 'cod',
'title' => $this->language->get('text_title'),
'terms' => '',
'sort_order' => $this->config->get('cod_sort_order')
);
}
return $method_data;
}
}
您可以添加以下条件:
if(isset($this->session->data['vouchers'])){
$status = false;
}
它对我有用。
如果您没有使用php的经验,请使用以下代码替换文件中的代码:
<?php
class ModelPaymentCOD extends Model {
public function getMethod($address, $total) {
$this->load->language('payment/cod');
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('cod_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
if ($this->config->get('cod_total') > 0 && $this->config->get('cod_total') > $total) {
$status = false;
} elseif (!$this->config->get('cod_geo_zone_id')) {
$status = true;
} elseif ($query->num_rows) {
$status = true;
} else {
$status = false;
}
if(isset($this->session->data['vouchers'])){
$status = false;
}
$method_data = array();
if ($status) {
$method_data = array(
'code' => 'cod',
'title' => $this->language->get('text_title'),
'terms' => '',
'sort_order' => $this->config->get('cod_sort_order')
);
}
return $method_data;
}
}