Post by Profitpro » Sat Dec 16, 2017 11:09 am

My apologies: The OC version is 2.1.0.1, the plugin is Store Pickup Shipping (Multiple locations) for Opencart, and the model file is now below.

So I have a custom shipping module and it works wonderful. However, I have added some code to input colors for the different shipping locations to be shown on the invoice, the admin, and passed as a hex value to the order table in the database. All works beautifully until I need the customer to check the radio button for the shipping method in the cart. The corresponding hex value for the shipping method is not passing. Only the last value in the array is passing to the order table. Even though the array is passing to template/checkout/shipping_method.tpl and the colors are correctly showing in the shipping method area in checkout. Now I need that value to pass in the hidden field to the order table in the database. Please help as I have searched and searched and there are no answers in the forum!

shipping_method.tpl code:

Code: Select all

<?php if ($error_warning) { ?>
<div class="alert alert-warning"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?></div>
<?php } ?>
<?php if ($shipping_methods) { ?>
<p><?php echo $text_shipping_method; ?></p>
<?php foreach ($shipping_methods as $shipping_method) { ?>
<p><strong><?php echo $shipping_method['title']; ?></strong></p>
<?php if (!$shipping_method['error']) { ?>
<?php foreach ($shipping_method['quote'] as $quote) { ?>
<div class="radio">
  <label style="color:<?php echo $quote['enhancepickup_color']; ?>">
    <?php if ($quote['code'] == $code || !$code) { ?>
    <?php $code = $quote['code']; ?>
    <?php $enhancepickup_color = $quote['enhancepickup_color']; ?>
       <input type="radio" name="shipping_method" value="<?php echo $quote['code']; ?>" checked="checked" />
      <input type="hidden" name="enhancepickup_color" value="<?php echo $quote['enhancepickup_color']; ?>" />
    <?php } else { ?>
    <input type="radio" name="shipping_method" value="<?php echo $quote['code']; ?>" />
    <input type="hidden" name="enhancepickup_color" value="<?php echo $quote['enhancepickup_color']; ?>" />
    <?php } ?>
    
    <?php echo $quote['title']; ?><?php echo $quote['enhancepickup_color']; ?></label>
   
</div>
<?php } ?>
<?php } else { ?>
<div class="alert alert-danger"><?php echo $shipping_method['error']; ?></div>
<?php } ?>
<?php } ?>
<?php } ?>
<p><strong><?php echo $text_comments; ?></strong></p>
<p>
  <textarea name="comment" rows="8" class="form-control"><?php echo $comment; ?></textarea>
</p>
<div class="buttons">
  <div class="pull-right">
    <input type="button" value="<?php echo $button_continue; ?>" id="button-shipping-method" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary" />
  </div>
</div>
Model file:

Code: Select all

<?php
class ModelShippingEnhancePickup extends Model {
    
	function getQuote($address) {
		$this->load->language('shipping/enhancepickup');
		$method_data = array();
		$status  = 1;
		if ($status) {
			$quote_data = array();
			$enhancepickup_title = $this->config->get('enhancepickup_title');
			$enhancepickup_desc = $this->config->get('enhancepickup_desc');
			$enhancepickup_cost = $this->config->get('enhancepickup_cost');
			$enhancepickup_total = $this->config->get('enhancepickup_total');
			$enhancepickup_geo = $this->config->get('enhancepickup_geo_zone_id');
			$enhancepickup_store_id = $this->config->get('enhancepickup_store_id');
			$enhancepickup_color = $this->config->get('enhancepickup_color');
			
			for($i=0; $i<count($enhancepickup_title); $i++){
				$geo_yes = 1;
				if(isset($enhancepickup_geo[$i]) && $enhancepickup_geo[$i]!=0){
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$enhancepickup_geo[$i] . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
					if ($query->num_rows) {
						$geo_yes = 1;
					}else{
						$geo_yes = '';
					}
				}
				$allowed_stores = array();
				if (isset($enhancepickup_store_id[$i])) {
					$allowed_stores = $enhancepickup_store_id[$i];	
				}
				if($this->cart->getSubTotal() >= $enhancepickup_total[$i] 
					&& $geo_yes 
					&& in_array($this->config->get('config_store_id'), $allowed_stores)){
				
					$quote_data['enhancepickup'.$i] = array(
						'code'         => 'enhancepickup.enhancepickup'.$i,
						'title'        => $enhancepickup_title[$i]." ( ".$enhancepickup_desc[$i]." )",
						'cost'         => $enhancepickup_cost[$i],
						'enhancepickup_color'  => $enhancepickup_color[$i],
						'tax_class_id' => 0,
						'text'         => $this->currency->format(
							$enhancepickup_cost[$i],
							isset($this->session->data['currency']) ? $this->session->data['currency'] : ''
						)
					);
		
					$method_data = array(
						'code'       => 'enhancepickup'.$i,
						'title'      => $this->language->get('text_title'),
						'quote'      => $quote_data,
						'enhancepickup_color' => $this->config->get('enhancepickup_color'),
						'sort_order' => $this->config->get('enhancepickup_sort_order'),
						'error'      => false
					);
				
				}
			}
		}
	
		return $method_data;
	}
}
?>
Last edited by Profitpro on Sun Dec 17, 2017 12:35 am, edited 1 time in total.

Newbie

Posts

Joined
Fri Jan 13, 2017 10:04 pm

Post by straightlight » Sat Dec 16, 2017 10:30 pm

No OC version posted. Incomplete solution posted. No model file of this shipping module posted along with template file.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Profitpro » Sun Dec 17, 2017 3:38 am

I have edited the original post to include version etc. Any help would be appreciated.

Newbie

Posts

Joined
Fri Jan 13, 2017 10:04 pm

Post by straightlight » Sun Dec 17, 2017 4:04 am

Since this issue is about an installed extension, contact the extension developer of that module. If no answer in return, simply use the site support link on the extension page.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by kestas » Sun Dec 17, 2017 5:24 pm

Hi, I think you don't need edit any file. You need edit only catalog... model file of your custom shipping module by adding some additional data to your $qoute_data of this file... This in case if developer did not help. I have not tried it but assume it the rigt way.

Custom OpenCart modules and solutions. Just PM me... Extensions you can find here and here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by straightlight » Sun Dec 17, 2017 10:28 pm

Hi, I think you don't need edit any file.
model file of your custom shipping module by adding some additional data to your $qoute_data of this file

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Profitpro » Mon Dec 18, 2017 9:18 pm

I have added the necessary data to $quote_data already. The array is working fine in the shopping cart you can see the colors on each shipping model when I add <?php echo $quote['enhancepickup_color']; ?> to see if the values for hex were being passed. They are. The issue is when the radio button is clicked for any of the shipping methods the correct hex value for that choice is not passed. Only the last value in the array is passed. Below is my model file for the shipping extension. Thank you for at least taking a look!

Code: Select all

<?php
class ModelShippingEnhancePickup extends Model {
    
	function getQuote($address) {
		$this->load->language('shipping/enhancepickup');
		$method_data = array();
		$status  = 1;
		if ($status) {
			$quote_data = array();
			$enhancepickup_title = $this->config->get('enhancepickup_title');
			$enhancepickup_desc = $this->config->get('enhancepickup_desc');
			$enhancepickup_cost = $this->config->get('enhancepickup_cost');
			$enhancepickup_total = $this->config->get('enhancepickup_total');
			$enhancepickup_geo = $this->config->get('enhancepickup_geo_zone_id');
			$enhancepickup_store_id = $this->config->get('enhancepickup_store_id');
			$enhancepickup_color = $this->config->get('enhancepickup_color');
			
			for($i=0; $i<count($enhancepickup_title); $i++){
				$geo_yes = 1;
				if(isset($enhancepickup_geo[$i]) && $enhancepickup_geo[$i]!=0){
					$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$enhancepickup_geo[$i] . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
					if ($query->num_rows) {
						$geo_yes = 1;
					}else{
						$geo_yes = '';
					}
				}
				$allowed_stores = array();
				if (isset($enhancepickup_store_id[$i])) {
					$allowed_stores = $enhancepickup_store_id[$i];	
				}
				if($this->cart->getSubTotal() >= $enhancepickup_total[$i] 
					&& $geo_yes 
					&& in_array($this->config->get('config_store_id'), $allowed_stores)){
				
					$quote_data['enhancepickup'.$i] = array(
						'code'         => 'enhancepickup.enhancepickup'.$i,
						'title'        => $enhancepickup_title[$i]." ( ".$enhancepickup_desc[$i]." )",
						'cost'         => $enhancepickup_cost[$i],
						'enhancepickup_color'  => $enhancepickup_color[$i],
						'tax_class_id' => 0,
						'text'         => $this->currency->format(
							$enhancepickup_cost[$i],
							isset($this->session->data['currency']) ? $this->session->data['currency'] : ''
						)
					);
		
					$method_data = array(
						'code'       => 'enhancepickup'.$i,
						'title'      => $this->language->get('text_title'),
						'quote'      => $quote_data,
						'enhancepickup_color' => $this->config->get('enhancepickup_color'),
						'sort_order' => $this->config->get('enhancepickup_sort_order'),
						'error'      => false
					);
				
				}
			}
		}
	
		return $method_data;
	}
}
?>

Newbie

Posts

Joined
Fri Jan 13, 2017 10:04 pm

Post by kestas » Tue Dec 19, 2017 3:54 pm

Hi,

only code title and cost passing to the database. So you can't do in this way like yours (do not add adittional line). You need add your additional data to the code line like this

Code: Select all

'code'         => 'enhancepickup.enhancepickup'.$i . '_' . $this->config->get('enhancepickup_color'),
After you make it you can parse this code to get your data where you need.
I have not tried it but logically should be like that.

Cheers

Custom OpenCart modules and solutions. Just PM me... Extensions you can find here and here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by Profitpro » Wed Dec 20, 2017 3:32 am

Thank you kestas! Seems to be getting closer but now I have the following error in the checkout process in Delivery Method.
Notice: Array to string conversion in /home/healthydirection/public_html/catalog/model/shipping/enhancepickup.php on line 37

Newbie

Posts

Joined
Fri Jan 13, 2017 10:04 pm

Post by straightlight » Wed Dec 20, 2017 3:36 am

replace:

Code: Select all

'code'         => 'enhancepickup.enhancepickup'.$i . '_' . $this->config->get('enhancepickup_color'),
with:

Code: Select all

'code'         => 'enhancepickup.enhancepickup' . $i . '_' . $enhancepickup_color[$i],

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Profitpro » Wed Dec 20, 2017 3:52 am

straightlight wrote:
Wed Dec 20, 2017 3:36 am
replace:

Code: Select all

'code'         => 'enhancepickup.enhancepickup'.$i . '_' . $this->config->get('enhancepickup_color'),
with:

Code: Select all

'code'         => 'enhancepickup.enhancepickup' . $i . '_' . $enhancepickup_color[$i],
Ok one step farther. Now I have an error Warning: Shipping method required! I am assuming this has something to do with validation in catalog/controller/checkout/shipping_method.php?

Newbie

Posts

Joined
Fri Jan 13, 2017 10:04 pm

Post by straightlight » Wed Dec 20, 2017 4:09 am

You must probably be talking about this line on shipping_method.php file:

Code: Select all

if (!isset($shipping[0]) || !isset($shipping[1]) || !isset($this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]])) {

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by kestas » Wed Dec 20, 2017 1:50 pm

Probably you changed the code string in method_data array... You should leave there this string:

Code: Select all

'code'       => 'enhancepickup'.$i,

Custom OpenCart modules and solutions. Just PM me... Extensions you can find here and here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am
Who is online

Users browsing this forum: No registered users and 7 guests