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>
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;
}
}
?>