Новосибирск +7(983)

По всем вопросам :

Телеграм : @radgura

JoomShopping - Добавить поле ввода адреса в способ доставки

У JoomShopping в стандартных способах доставки нет возможности указать адрес доставки или транспортную компнию, это можно исправить.

Редактируем файлы формы:

components/com_jshopping/templates/<ваш шаблон>/checkout/shippings.php

Переменные будет созранять в сессии, для этого добавим код:

if (!isset($_SESSION['jsext_field_3'])) $_SESSION['jsext_field_3']='';
if (!isset($_SESSION['jsext_field_1'])) $_SESSION['jsext_field_1']='';
if (!isset($_SESSION['jsorder_id'])) $_SESSION['jsorder_id']='';

Далее добавим поля для ввода, у нас в примере была 6 способов доставки:

1 - Доставка курьером по г.Новосибисрку
2 - Доставка Почтой России. оптовая
3 - Доставка транспортной компанией
4 - Самовывоз из нашего офиса
5 - Доставка Почтой России. розничная
6 - Самовывоз из нашего офиса. розничная

<div class="name">
<input type = "radio" name = "sh_pr_method_id" class="changeshipping" id="shipping_method_<?php print $shipping->sh_pr_method_id?>" value="<?php print $shipping->sh_pr_method_id ?>" <?php if ($shipping->sh_pr_method_id==$this->active_shipping){ ?>checked = "checked"<?php } ?> onclick="showShippingForm(<?php print $shipping->shipping_id?>)" />
<label for = "shipping_method_<?php print $shipping->sh_pr_method_id ?>" class="changeshipping" id="labelshipping_method_<?php print $shipping->sh_pr_method_id?>"><?php echo '<b>'.$ii.'.</b> ';?><?php
if ($shipping->image){?>
<span class="shipping_image"><img src="/<?php print $shipping->image?>" alt="<?php print htmlspecialchars($shipping->name)?>" /></span>
<?php }?>
<b><?php print $shipping->name?></b>
<span class="shipping_price">(<?php print formatprice($shipping->calculeprice); ?>)</span>
</label>

<?php if ($this->config->show_list_price_shipping_weight && count($shipping->shipping_price)){ ?>
<table class="shipping_weight_to_price">
<?php
foreach($shipping->shipping_price as $price)
{?>
<tr>
<td class="weight">
<?php if ($price->shipping_weight_to!=0){ print formatweight($price->shipping_weight_from);?> - <?php print formatweight($price->shipping_weight_to);}else{ print _JSHOP_FROM." ".formatweight($price->shipping_weight_from);} ?>
</td>
<td class="price">
<?php print formatprice($price->shipping_price); ?>
</td>
</tr>
<?php } ?>
</table>
<?php } ?>

<div class="shipping_descr"><?php print $shipping->description?></div>
<?php
$ext1val='';
if ($shipping->sh_pr_method_id==1) $ext1val='Доставка курьером по Новосибирску.';//розница
if ($shipping->sh_pr_method_id==2) $ext1val='Доставка Почтой России.';//оптовые
if ($shipping->sh_pr_method_id==3)
{
if ($_SESSION['jsext_field_1']=='Доставка Почтой России.') $_SESSION['jsext_field_1']='';
if ($_SESSION['jsext_field_1']=='Самовывоз из офиса.') $_SESSION['jsext_field_1']='';
if ($_SESSION['jsext_field_1']=='Доставка курьером по Новосибирску.') $_SESSION['jsext_field_1']='';
$ext1val=$_SESSION['jsext_field_1'];
};
if ($shipping->sh_pr_method_id==4) $ext1val='Самовывоз из офиса.';
if ($shipping->sh_pr_method_id==5) $ext1val='Доставка Почтой России.';
if ($shipping->sh_pr_method_id==6) $ext1val='Самовывоз из офиса.';
?>
<input class="to_ext3" type="text" value="<?php echo $ext1val;?>" id="shipping_text1_<?php print $shipping->sh_pr_method_id?>" placeholder="Укажите транспортную компанию" style="<?php if ($shipping->sh_pr_method_id!=$this->active_shipping or !in_array($this->active_shipping,array(3))) echo 'display:none;'?>width: 99%;max-width:720px;margin-bottom: 10px;">
<textarea class="to_ext3" id="shipping_text3_<?php print $shipping->sh_pr_method_id?>" style="<?php if ($shipping->sh_pr_method_id!=$this->active_shipping) echo 'display:none;'?>min-height:70px;width:99%;max-width:720px;" placeholder="<?php echo JText::_('SHIPPING_TXT_'.$shipping->sh_pr_method_id);?>"><?php echo $_SESSION['jsext_field_3']?></textarea>
<div id="shipping_form_<?php print $shipping->shipping_id?>" class="shipping_form <?php if ($shipping->sh_pr_method_id==$this->active_shipping) print 'shipping_form_active'?>"><?php print $shipping->form?></div>
<?php if ($shipping->delivery)
{?>
<div class="shipping_delivery"><?php print _JSHOP_DELIVERY_TIME.": ".$shipping->delivery?></div>
<?php }?>
<?php if ($shipping->delivery_date_f){?>
<div class="shipping_delivery_date"><?php print _JSHOP_DELIVERY_DATE.": ".$shipping->delivery_date_f?></div>
<?php }?>
</div>

Добавим также скрытые элементы для хранения результата выбора - его будем передовать для сохранения в сессии.

<input type="hidden" name="ext_field_3" id="ext_field_3" value="<?php echo $_SESSION['jsext_field_3']?>" class="input">
<input type="hidden" name="ext_field_1" id="ext_field_1" value="<?php echo $_SESSION['jsext_field_1']?>" class="input">

Скрипт, котрый перебросит набранный текст и отправит его для внесения в сессию:

<script>
jQuery(document).ready(function() {
jQuery('body').on( "click",".changeshipping", function(){
var ids=this.id.split('_')[2];
var txt3=document.getElementById('shipping_text3_'+ids).value;
var txt1=document.getElementById('shipping_text1_'+ids).value;
txt3=txt3.replace("'",'&#39;').replace('`','&#96;').replace('+','&#43;').replace('+','&#61;');
txt1=txt1.replace("'",'&#39;').replace('`','&#96;').replace('+','&#43;').replace('+','&#61;');
if (document.getElementById('ext_field_3')!=null) document.getElementById('ext_field_3').value=txt3;
if (document.getElementById('ext_field_1')!=null) document.getElementById('ext_field_1').value=txt1;
jQuery('.to_ext3').hide();
if (ids!='4' && ids!='6')jQuery('#shipping_text3_'+ids).show(); //Полный адрес - только доставка с адресом
if (ids=='3')jQuery('#shipping_text1_'+ids).show(); //Траспортная - только доставка траспортной
});
jQuery('body').on( "change",".to_ext3", function(){
var ids=this.id.split('_')[2];
var txt3=document.getElementById('shipping_text3_'+ids).value;
var txt1=document.getElementById('shipping_text1_'+ids).value;
txt3=txt3.replace("'",'&#39;').replace('`','&#96;').replace('+','&#43;').replace('+','&#61;');
txt1=txt1.replace("'",'&#39;').replace('`','&#96;').replace('+','&#43;').replace('+','&#61;');
if (document.getElementById('ext_field_3')!=null) document.getElementById('ext_field_3').value=txt3;
if (document.getElementById('ext_field_1')!=null) document.getElementById('ext_field_1').value=txt1;
var myData='setextra='+ids+'&txt3='+txt3+'&txt1='+txt1;
jQuery.ajax({
type: "POST",
url: "index.php",
dataType:"text",
data:myData,
success:function(response){},
error:function (xhr, ajaxOptions, thrownError){alert(thrownError);}
});
});
});
</script>

Далее необходимперехват POST запроса и внесение в сессию, можно добавить на главной странице:

if (isset($_POST['setextra']) and strlen($_POST['setextra']))
{
$ids=$_POST['setextra'];
$txt1=$_POST['txt1'];
$txt3=$_POST['txt3'];
$_SESSION['jsext_field_3']=$txt3;
$_SESSION['jsext_field_1']=$txt1;
$_SESSION['jsorder_id']=$ids;
exit();
}

Осталось только внести в заказ, редактируем файл:

components/com_jshopping/models/checkoutorder.php
public function orderDataSave(&$adv_user, &$post){
$jshopConfig = JSFactory::getConfig();
$dispatcher = JDispatcher::getInstance();
$session = JFactory::getSession();
$cart = $this->getCart();
$order = $this->createOrder($adv_user, $post);
$dispatcher->trigger('onAfterCreateOrder', array(&$order, &$cart));
$this->couponFinished($adv_user->user_id, $order);
$order->saveOrderItem($cart->products);
$dispatcher->trigger('onAfterCreateOrderFull', array(&$order, &$cart));
$this->setEndOrderId($order->order_id);
$order->saveOrderHistory(1, '');
$order->updateProductsInStock(1);
$db = JFactory::getDbo();
if (isset($_SESSION['jsext_field_3']) and strlen($_SESSION['jsext_field_3'])>0)
{
//полный адрес
$db->setquery("update #__jshopping_orders set ext_field_3='".$_SESSION['jsext_field_3']."',D_ext_field_3='".$_SESSION['jsext_field_3']."' where order_id='".$order->order_id."' ");
$db->execute();
}
if (isset($_SESSION['jsext_field_1']) and strlen($_SESSION['jsext_field_1'])>0)
{
//транспортная
$db->setquery("update #__jshopping_orders set ext_field_1='".$_SESSION['jsext_field_1']."',d_ext_field_1='".$_SESSION['jsext_field_1']."' where order_id='".$order->order_id."' ");
$db->execute();
}
if ($jshopConfig->send_order_email && $order->order_created){$send = $this->sendOrderEmail($order->order_id);}
return $order;
}

Комментарии (0)

Здесь ещё нет оставленных комментариев.

Оставьте свой комментарий

  1. Добавление комментария от гостя.
Вложения (0 / 3)
Share Your Location

Как с нами связаться

По всем вопросам пишите  

Телеграм: @radgura

OnLine заказ

Отправить сообщение

Нажимая на кнопку «Отправить сообщение», я соглашаюсь:
* с условиями публичной оферты
* обработку моих персональных данных


RAD компоненты

Please publish modules in offcanvas position.