Всем привет!
Помогите в решении проблемы:
Заказчик просит реализовать на сайте помимо стандартной кнопки "Купить", кнопку быстрый заказ, только функционал у нее не совсем обычный. При клике на кнопку, клиент должен автоматом попадать на страницу "Оформление заказа". Решил реализовать это с помощью модуля , создал дубль основной кнопки, получилось вот что:
<div class="cart">
<div><?php echo $text_qty; ?>
<input type="text" name="quantity" size="2" value="<?php echo $minimum; ?>" />
<input type="hidden" name="product_id" size="2" value="<?php echo $product_id; ?>" />
<input type="button" value="<?php echo $button_cart; ?>" id="button-cart" class="button" />
</div>
<div class="cart">
<div><?php echo $text_qty; ?>
<input type="text" name="quantity" size="2" value="<?php echo $minimum; ?>" />
<input type="hidden" name="product_id" size="2" value="<?php echo $product_id; ?>" />
<input type="button1" value="<?php echo $button_cart1; ?>" id="button-cart1" class="button" />
</div>
вот VQMOD, который реализует переход при клике на оформление заказа:
<!-- *********************************************************************************** -->
<!-- *** Part of OpenShop project: http://OpenShop.org.ua (c) MaxD *** -->
<!-- *********************************************************************************** -->
<!-- Redistribution in any form without written permission is prohibited. -->
<modification>
<id><![CDATA[Removes cart and transforms "Add to cart" buttons into "Buy" buttons that lead directly to checkout.]]></id>
<version><![CDATA[1.7]]></version>
<vqmver><![CDATA[]]></vqmver>
<author><![CDATA[MaxD http://OpenShop.org.ua]]></author>
<file name="catalog/view/theme/*/template/product/product.tpl">
<!-- Remove quantity selection start -->
<operation error="skip">
<search position="replace"><![CDATA[<?php echo $text_qty; ?>]]></search>
<add><![CDATA[]]></add>
</operation>
<operation error="skip">
<search position="replace"><![CDATA[name="quantity"]]></search>
<add><![CDATA[name="quantity" style="display:none;"]]></add>
</operation>
<!-- Remove quantity selection end -->
<operation error="skip">
<search position="replace" offset="6"><![CDATA[$('#notification').html]]></search>
<add><![CDATA[location='<?php echo $this->url->link('checkout/checkout', '', 'SSL') ?>';]]></add>
</operation>
</file>
<!-- Make the magic -->
<file name="catalog/controller/checkout/cart.php">
<operation error="skip">
<search position="before"><![CDATA[$this->cart->add($this->request->post['product_id'], $quantity, $option]]></search>
<add><![CDATA[$this->cart->clear();]]></add>
</operation>
<operation error="skip">
<search position="after"><![CDATA[$json['total'] = sprintf]]></search>
<add><![CDATA[$json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');]]></add>
</operation>
</file>
<!-- Change "Add to cart" button to "Buy" button in all languages: start -->
<file name="catalog/language/*/*.php">
<operation error="skip">
<search position="replace"><![CDATA[$_['button_cart']]]></search>
<add><![CDATA[global $os; if (empty($os['buy_button']) or (strlen($os['buy_button'])<2)) $os['buy_button'] = 'Buy'; $_['button_cart'] = $os['buy_button'];//]]></add>
</operation>
</file>
<!-- Change "Add to cart" button to "Buy" button in all languages: end -->
<file name="catalog/view/theme/*/template/common/header.tpl">
<operation error="skip">
<search position="replace"><![CDATA[<?php echo $cart; ?>]]></search>
<add><![CDATA[]]></add>
</operation>
<operation error="skip">
<search position="replace"><![CDATA[<a href="<?php echo $shopping_cart; ?>"><?php echo $text_shopping_cart; ?></a>]]></search>
<add><![CDATA[]]></add>
</operation>
<operation error="skip">
<search position="replace"><![CDATA[<a href="<?php echo $checkout; ?>"><?php echo $text_checkout; ?></a>]]></search>
<add><![CDATA[]]></add>
</operation>
</file>
</modification>
не могу понять как следует изменить код, который отвечает за клик по кнопке, чтобы он в первом варианте переходил на страницу оформление заказа, а во втором случае работал как стандартная кнопка "Купить":
<script type="text/javascript"><!--
$('#button-cart').bind('click', function() {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, information, .error').remove();
if (json['error']) {
if (json['error']['option']) {
for (i in json['error']['option']) {
$('#option-' + i).after('<span class="error">' + json['error']['option'][i] + '</span>');
}
}
}
if (json['success']) {
$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('.success').fadeIn('slow');
$('#cart-total').html(json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
}
});
});
//--></script>
<script type="text/javascript"><!--
$('#button-cart1').bind('click', function() {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, information, .error').remove();
if (json['error']) {
if (json['error']['option']) {
for (i in json['error']['option']) {
$('#option-' + i).after('<span class="error">' + json['error']['option'][i] + '</span>');
}
}
}
if (json['success']) {
$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('.success').fadeIn('slow');
$('#cart-total').html(json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
}
});
});
сейчас при установке мода, при клике на обе кнопки происходит переход на "оформление заказа"
Заранее благодарен!