Page 1 of 1

hide or disable cod option if a particular option value selected

Posted: Sat Apr 07, 2018 6:56 pm
by kg0925
hello, i am using opencart version 1.5.6.4 i just want to add a function to cod payment mode. if a perticular option's any value selected then cod option should be disappear from checkout page. i am running a women's clothing website where i want to provide stitching service and want this modification. ex. i have a option " Stitching" and their values are M, L, XL if customer select any of values from stitching option then cod must be disabled or hidden from check out page. any one have idea how to do this? i searched for the extension but couldn't find

Re: hide or disable cod option if a particular option value selected

Posted: Sat Apr 07, 2018 9:46 pm
by straightlight
According to this topic: https://stackoverflow.com/questions/272 ... p-the-keys , the array_column is meant for PHP 7. The reason why the results may be failing for you is because your server may not be upgraded to PHP 7. Otherwise, you'd need to use the old ways with the array mapping which is no longer necessary with PHP 7.

Re: hide or disable cod option if a particular option value selected

Posted: Mon Apr 09, 2018 2:21 pm
by kg0925
Thanks for your quick reply. the_option_value should i change with option name 'size' or their values like 'M, L , XL, XXL'. i tried both way but it's not working. it's still showing cod option during checkout.

Re: hide or disable cod option if a particular option value selected

Posted: Tue Apr 10, 2018 4:21 am
by straightlight
I just realized the status should be set to false. Not true. See if the last part of the instructions works when entering the option value with this:

Code: Select all

} elseif (in_array('the_option_value', $option_values)) {
			$status = false;

Re: hide or disable cod option if a particular option value selected

Posted: Tue Apr 10, 2018 1:06 pm
by kg0925
still it's not working. i made this vqmod for this mod

Code: Select all

<modification>
	<id> disable cod for stitching option</id>
	<version>1.1.0</version>
	<vqmver>1.1.0</vqmver>
	<author>custom</author>

	<file name="catalog/model/payment/cod.php file">
		<operation error="skip">
			<search position="before"><![CDATA[if ($this->config->get('cod_total') > 0 && $this->config->get('cod_total') > $total) {]]></search>
			<add><![CDATA[$products = $this->cart->getProducts();
		
		foreach ($products as $product) {
			$option_data = array();

			foreach ($product['option'] as $option) {
				if ($option['type'] != 'file') {
					$value = $option['option_value'];
				} else {
					$filename = $this->encryption->decrypt($option['option_value']);

					$value = utf8_substr($filename, 0, utf8_strrpos($filename, '.'));
				}

				$option_data[] = array(
					'name'  => $option['name'],
					'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
				);
			}
		}
		
		$option_values = array_column($option_data, 'value');]]></add>
		</operation>
<operation>
			<search position="before"><![CDATA[} else {
			$status = false;]]></search>
			<add><![CDATA[} elseif (in_array('Stitching', $option_values)) {                      // i also applied option values but not working both way
			$status = false;]]></add>
		</operation>

	</file>
</modification> 
stitching is the option name and their values are M, L , XL i tried with both way option name and their values. also made the status false but still it's not working.

Re: hide or disable cod option if a particular option value selected

Posted: Tue Apr 10, 2018 7:36 pm
by straightlight
After creating this XML file, use the VQMod Manager extension from the Marketplace to see if you have any error structure in the XML file itself or having any conflicts.

Re: hide or disable cod option if a particular option value selected

Posted: Fri Apr 13, 2018 2:54 pm
by kg0925
i am already using vqmod manager. but it's not showing any kind of error in vqmod manager.

Re: hide or disable cod option if a particular option value selected

Posted: Fri Apr 13, 2018 6:46 pm
by straightlight
Is your request about an option value as per your topic title indicates or rather a product option value you are looking for to track?

Re: hide or disable cod option if a particular option value selected

Posted: Fri Apr 13, 2018 7:47 pm
by kg0925
option value

Re: hide or disable cod option if a particular option value selected

Posted: Fri Apr 13, 2018 7:54 pm
by straightlight
I have now edited the steps above: viewtopic.php?f=22&t=203471&p=720189#p720189 . You were looking to use the option names, not the option values.

Re: hide or disable cod option if a particular option value selected

Posted: Fri Apr 13, 2018 11:12 pm
by kg0925
still it's not working. also it's not showing any error in vqmod

Re: hide or disable cod option if a particular option value selected

Posted: Fri Apr 13, 2018 11:28 pm
by straightlight
See if there are errors showing in the error logs.

Re: hide or disable cod option if a particular option value selected

Posted: Sat Apr 14, 2018 1:39 pm
by kg0925
That is the problem it's not showing any error in vqmod manager and in error logs.

Re: hide or disable cod option if a particular option value selected

Posted: Sat Apr 14, 2018 9:50 pm
by straightlight
Clear your OC cache from your system/cache folder (excluding index.html file)

Re: hide or disable cod option if a particular option value selected

Posted: Mon Apr 16, 2018 8:55 pm
by straightlight
I have now edited the instructions above to upgrade to PHP 7 and pointed out the Stackoverflow topic in the mean time.

Re: hide or disable cod option if a particular option value selected

Posted: Wed Apr 18, 2018 8:59 pm
by kg0925
i appreciate your effort and your valuable time to answer this query. my server is running on 5.6.23 php version. and i am not a programmer. i just have some basic knowledge about programming. so i don't know where to change what kind of change i need for array mapping.

Re: hide or disable cod option if a particular option value selected

Posted: Thu Apr 19, 2018 8:49 am
by straightlight
Since you're using OC v1.5x releases, it is also quite old. I would suggest to upgrade to at least v2.3.0.2 release for PHP compatibility improvement.

Re: hide or disable cod option if a particular option value selected

Posted: Mon Aug 27, 2018 3:18 pm
by kg0925
straightlight wrote:
Thu Apr 19, 2018 8:49 am
Since you're using OC v1.5x releases, it is also quite old. I would suggest to upgrade to at least v2.3.0.2 release for PHP compatibility improvement.
hello i have updated my opencart store to version 3.0.2.0 on php 7 so now any suggestion for this mod?

Re: hide or disable cod option if a particular option value selected

Posted: Mon Aug 27, 2018 7:04 pm
by straightlight
Since you are now using v3.0.2.0 release, I would suggest posting in the v3.x releases section of the forum. However, since this is about custom coding requests, in either case, I would suggest to post in the Commercial Support section of the forum to get this done as a custom job.