Jump to content

Recommended Posts

Здравствуйте! Помогите передать стоимость доставки с cart.tpl в order.tpl

Зачем? Дело в том, что я поставил калькулятор сдека, он меняет стоимость доставки в соответствии с городом получателем, вот мне и надо эту сумму передать в заказ, админку и на эл. почту.

Пример: http://odejala-podushki.ru/products/test_

Вот код с cart.tpl 

   {* Доставка *}
{if $deliveries}
<ul id="deliveries">
<h2><b>1</b> Выберите способ доставки:</h2>
	{foreach $deliveries as $delivery}
	<li>
		<div class="checkbox">
			<input type="radio" name="delivery_id" value="{$delivery->id}" {if $delivery_id==$delivery->id}checked{elseif $delivery@first}checked{/if} id="deliveries_{$delivery->id}">
		</div>
		
			<h3>
			<label for="deliveries_{$delivery->id}">
			{$delivery->name}
			{if $cart->total_price < $delivery->free_from && $delivery->price>0}
				{if $delivery->id == 6}(<span class="price" id="clonecdek">{$delivery->price|convert}</span> руб.)
                                {else}(<span class="price">{$delivery->price|convert}</span> {$currency->sign}){/if}
			{elseif $cart->total_price >= $delivery->free_from}
				{if $delivery->id == 6}(<span class="price" id="clonecdek">от 0</span> руб.)
                                {else}(<span class="price none">0</span>бесплатно){/if}
			{/if}
                        
			</label>
			</h3>
                        {if $delivery->id == 6}
                        {if $cart->total_price < $delivery->free_from && $delivery->price>0}                   
{include file='form_do3.tpl'}
{elseif $cart->total_price >= $delivery->free_from}
{include file='form_ot3.tpl'}{/if}
{/if}
			<div class="description">
			{$delivery->description}
			</div>
	</li>
	{/foreach}
</ul>
{/if}
</td></tr></table>
</form><br>
{else}
  В корзине нет товаров
{/if}
{literal}
	<script type="text/javascript">
	$(document).ready(function(){
		$("input:radio[name='delivery_id']").live("click", function(){
			if($("input:radio[name='delivery_id']:checked").val() == "2"){
				$("#addr").css("display","none");
			}else{
				$("#addr").css("display","block");
			}
		});
                $("input:radio[name='delivery_id']").live("click", function(){
			if($("input:radio[name='delivery_id']:checked").val() == "7"){
				$(".pickpoint").css("display","block");
			}else{
				$(".pickpoint").css("display","none");
			}
		});
                $("input:radio[name='delivery_id']").live("click", function(){
			if($("input:radio[name='delivery_id']:checked").val() == "6"){
				 $(".cdekk").css("display","block");
			}else{
                                 $(".cdekk").css("display","none");
			}
		});
	});
        function my_function(result){
			// устанавливаем в скрытое поле ID терминала
			document.getElementById('pickpoint_id').value=result['id'];			
			// показываем пользователю название точки и адрес доствки
			document.getElementById('address').value=result['address']+'. '+result['name'];
		}
        $(function() {
	function calctotal(){
		var total = parseInt($('table th.price > span').text().replace(/\s+/g, '')), radio;
		total = total?total:0;
		if (radio = $("input[type='radio']:checked")){
			var add = parseInt($(radio).parents('li').find('span.price').text().replace(/\s+/g, ''));
			add = (add)?(add):(0);
			total+=add;		
		}
		$('#total > span').text(total);
	}
	$('input[type=radio]').change(function() {
		calctotal();
	});
	calctotal();
});
	</script>  
{/literal}

передать нужно из <span class="price" id="clonecdek">....</span>

Link to post
Share on other sites

Если кому понадобится сделал так:

в папке view, файл CartView.php

1 добавил ниже этого

    	$order->delivery_id = $this->request->post('delivery_id', 'integer');

вот это 

		$order->delivery_price = $this->request->post('delivery_price', 'float');

получилось

    	$order->delivery_id = $this->request->post('delivery_id', 'integer');
	$order->delivery_price = $this->request->post('delivery_price', 'float');

 

 

2 далее заменить: 

		$this->design->assign('delivery_id', $order->delivery_id); 

на

                $this->design->assign('delivery_price', $order->delivery_price);
 

 

3 и заменить это 

	    	// Стоимость доставки
			$delivery = $this->delivery->get_delivery($order->delivery_id);
	    	if(!empty($delivery) && $delivery->free_from > $order->total_price)

на это

	    	// Стоимость доставки
			$delivery = $this->delivery->get_delivery($order->delivery_price);
	    	if(!empty($delivery) && $delivery->free_from > $order->total_price)

теперь мы можем передать {$order->delivery_price}  с cart.tpl в order.tpl

 

в шаблоне cart.tpl

много чего поменял:

   {* Доставка *}
{if $deliveries}
<ul id="deliveries">
<h2><b>1</b> Выберите способ доставки:</h2>
	{foreach $deliveries as $delivery}
	<li>
		<div class="checkbox">
			<input onclick="select_delivery_method({$delivery->id});" type="radio" name="delivery_id" value="{$delivery->id}" {if $delivery_id==$delivery->id}checked{elseif $delivery@first}checked{/if} id="deliveries_{$delivery->id}">
		</div>
		
			<h3>
			<label for="deliveries_{$delivery->id}">
			{$delivery->name}
			{if $cart->total_price < $delivery->free_from && $delivery->price>0}
				{if $delivery->id == 3}(<span class="price" id="delivery_price_{$delivery->id}">{$delivery->price|convert}</span> руб.)
                                {else}(<span class="price" id="delivery_price_{$delivery->id}">{$delivery->price|convert}</span> {$currency->sign})
                                {/if}
			{elseif $cart->total_price >= $delivery->free_from}
				{if $delivery->id == 3}(<span class="teprice">от </span><span id="delivery_price_{$delivery->id}">0</span> руб.)
                                {else}(<span class="price none" id="delivery_price_{$delivery->id}">0</span>бесплатно){/if}
			{/if}
                        
			</label>
			</h3>
                        {if $delivery->id == 3}
                        {if $cart->total_price < $delivery->free_from && $delivery->price>0}                   
{include file='form_do3.tpl'}
{elseif $cart->total_price >= $delivery->free_from}
{include file='form_ot3.tpl'}{/if}
{/if}
			<div class="description">
			{$delivery->description}
			</div>
	</li>
	{/foreach}
</ul>
<input id="deliverys" type=text name=delivery_price value="{$order->delivery_price}">
{/if}
</td></tr></table>
</form><br>
{else}
  В корзине нет товаров
{/if}
{literal}
	<script type="text/javascript">
	$(document).ready(function(){
		$("input:radio[name='delivery_id']").live("click", function(){
			if($("input:radio[name='delivery_id']:checked").val() == "2"){
				$("#addr").css("display","none");
			}else{
				$("#addr").css("display","block");
			}
		});
                $("input:radio[name='delivery_id']").live("click", function(){
			if($("input:radio[name='delivery_id']:checked").val() == "4"){
				$(".pickpoint").css("display","block");
			}else{
				$(".pickpoint").css("display","none");
			}
		});
                $("input:radio[name='delivery_id']").live("click", function(){
			if($("input:radio[name='delivery_id']:checked").val() == "3"){
				 $(".cdekk").css("display","block");
			}else{
                                 $(".cdekk").css("display","none");
			}
		});
                
                $(".ot").live("click", function(){
                        $(".teprice").css("display","none");
	});      
                
                
        });      
        function my_function(result){
			// устанавливаем в скрытое поле ID терминала
			document.getElementById('pickpoint_id').value=result['id'];			
			// показываем пользователю название точки и адрес доствки
			document.getElementById('address').value=result['address']+'. '+result['name'];
		}

	</script>  
            
{/literal}
<script>
function select_delivery_method(method_id)
{
radiobuttons = document.getElementsByName('delivery_id');
for(var i=0;i<radiobuttons.length;i++)
{
if(radiobuttons[i].value == method_id)
{
radiobuttons[i].checked = 1;
}
}
var subtotal = parseFloat(document.getElementById('sub_price').innerHTML);
var delivery = 0;
if(document.getElementById('delivery_price_'+method_id))
delivery = parseFloat(document.getElementById('delivery_price_'+method_id).innerHTML);
total = subtotal+delivery;

document.getElementById('subtotal_price').innerHTML = total; 
document.getElementById('delivery').innerHTML = delivery;
document.getElementById('deliverys').value = delivery;
}
</script>
<script>
select_delivery_method(1);
</script>
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...