Page 1 of 1

Hide Other Shipping (if free shipping active) and in addition hide Free shipping if active for a customer Group

Posted: Thu Feb 28, 2019 7:51 am
by mukur
Opencart Version 2.3.0.2 - currently using Vqmod (below) to hide other shipping when free shipping is active. I am looking to adapt it to also hide free shipping if active for a particular Customer group = '2" (i.e. Wholesale customers will not see\be allowed free shipping option).


<file path="catalog/model/extension/shipping/*.php">
<operation error="skip">
<search><![CDATA[if ($status) {]]></search>
<add position="before"><![CDATA[
if (get_class($this)!='ModelExtensionShippingFree') {
if (($this->config->get('free_status') == 1) && (float)$this->cart->getTotal() >= $this->config->get('free_total')) {
$status = false;
}
}
]]></add>
</operation>
</file>

Currently going round in circles, should be fairly simple but unfortunately cant crack it - any help would be appreciated.

Cheers

Re: Hide Other Shipping (if free shipping active) and in addition hide Free shipping if active for a customer Group

Posted: Thu Feb 28, 2019 8:10 am
by straightlight
From the provided XML code, replace:

Code: Select all

if (get_class($this)!='ModelExtensionShippingFree') {
if (($this->config->get('free_status') == 1) && (float)$this->cart->getTotal() >= $this->config->get('free_total')) {
$status = false;
}
}
with:

Code: Select all

$this->load->model('account/customer_group');

$customer_groups = $this->model_account_customer_group->getCustomerGroups();

$customer_group_ids = array_column($customer_groups, 'customer_group_id');

$customer_group_ids_intersect = array_intersect($customer_group_ids, array(2)); // You can add more IDs here.

if (((!$this->config->get('free_status')) || ($this->config->get('free_status') && (float)$this->cart->getTotal() > $this->config->get('free_total') && (in_array($this->config->get('config_customer_group_id'), (array)$customer_group_ids_intersect))))) {
	$status = false;	
}

Re: Hide Other Shipping (if free shipping active) and in addition hide Free shipping if active for a customer Group

Posted: Thu Feb 28, 2019 10:40 am
by mukur
Thanks Straightlight

Going in the right direction tried your code but unfortunately does not quite do what I want

For:
Default Customer - does not hide other shipping methods when "free shipping" is available

Wholesale above free shipping limit get the message "Warning: No Shipping options are available. Please contact us for assistance!" rather than showing the shipping methods available i.e "weight based"

Cheers

Re: Hide Other Shipping (if free shipping active) and in addition hide Free shipping if active for a customer Group

Posted: Thu Feb 28, 2019 8:33 pm
by straightlight
mukur wrote:
Thu Feb 28, 2019 10:40 am
Thanks Straightlight

Going in the right direction tried your code but unfortunately does not quite do what I want

For:
Default Customer - does not hide other shipping methods when "free shipping" is available

Wholesale above free shipping limit get the message "Warning: No Shipping options are available. Please contact us for assistance!" rather than showing the shipping methods available i.e "weight based"

Cheers
The default customer group was not mentioned in your topic subject nor on the first post. As for the wholesale, it doesn't explain much other than what the customer group name is according to your first post. However, not to hide other shipping methods when free shipping is available would need to be done from the controllers, not from the models. You're simply on the wrong location to set the conditionings.

Re: Hide Other Shipping (if free shipping active) and in addition hide Free shipping if active for a customer Group

Posted: Fri Mar 01, 2019 4:03 am
by mukur
Thanks again for input Straightlight

Apologies if my posts were confusing. The vqmod code posted in my 1st post actually successfully manages to hide other shipping methods when free shipping level is reached for both default and wholesale customers. I thought it would just be a simple tweak to get it so that free shipping would not apply(or be hidden) for Wholesale customers.

Cheers,

Update: pretty easy fix in the end just needed to include an "else if " in the code but took me a hell of a time and frustration to figure it out - hope it helps someone else

Code: Select all

if ($this->customer->getGroupId() != 1) {
            } elseif 

Re: Hide Other Shipping (if free shipping active) and in addition hide Free shipping if active for a customer Group

Posted: Sun May 12, 2019 1:36 pm
by rebelo
Hi.

This might be what i have been looking for for a long time.
In Opencart 2.1.0.2 i need to hide at checkout payment_B when payment_A is also available.

Got so far

Code: Select all

<file name="catalog/model/payment/*.php">
		<operation error=skip">
			<search position="before"><![CDATA[
			if (get_class($this)!='ModelPayment_A')
			
Any help for the rest pls.

Re: Hide Other Shipping (if free shipping active) and in addition hide Free shipping if active for a customer Group

Posted: Mon May 13, 2019 2:14 am
by rebelo
Still not working
<file name="catalog/model/payment/*.php">
<operation error="skip">
<search><![CDATA[if ($status) {]]></search>
<add position="before"><![CDATA[
if (get_class($this)!='ModelPaymentMultibanco') {
($this->config->get('bank_transfer'){
$status = false;
}
}
]]></add>
</operation>
</file>
</modification>

Re: Hide Other Shipping (if free shipping active) and in addition hide Free shipping if active for a customer Group

Posted: Tue May 14, 2019 3:13 am
by rebelo
Hi.

Solved with Restrict Payment Methods.

Rebelo