Поступила задача предоставить скику от суммы и кол-ва заказов.
Для реализации создадим файл с функцией расчета скидки
Вы можете получить доступ,купив эту доработку
Добавим пересчет стоимости заказа со скидка, файл
plugins/system/onepage_generic/cart/ajaxprice.php
<?php
/**
** Parts of this code is written by joomlapro.com Copyright (c) 2012, 2015 All Right Reserved.
** Many part of this code is from VirtueMart Team Copyright (c) 2004 - 2015. All rights reserved.
** Some parts might even be Joomla and is Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
** http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
** This source is free software. This version may have been modified pursuant
** to the GNU General Public License, and as distributed it includes or
** is derivative of works licensed under the GNU General Public License or
** other free or open source software licenses.
**
** THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
** KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
** PARTICULAR PURPOSE.
** <author>Joomlaproffs / Virtuemart team</author>
** <email>Этот адрес электронной почты защищён от спам-ботов. У вас должен быть включен JavaScript для просмотра.;/email>
** <date>2017</date>
*/
defined('_JEXEC') or die('Restricted access');
include_once(JPATH_ROOT.DIRECTORY_SEPARATOR.'radfunc.php');
$cart->prepareCartData();
$i = 0;
foreach($cart->pricesUnformatted as $id=>$value)
{
if(!is_array($value) && is_string($id))
{
continue;
}
$price_values["products"][$id]["subtotal_salesPrice"]=!empty($cart->pricesUnformatted[$id]["salesPrice"])?$currency->priceDisplay($cart->pricesUnformatted[$id]["salesPrice"]):"";
$price_values["products"][$id]["subtotal_tax_amount"]=!empty($cart->pricesUnformatted[$id]["taxAmount"])?$currency->priceDisplay($cart->pricesUnformatted[$id]["taxAmount"], 0, $cart->products[$id]->quantity):"";
$price_values["products"][$id]["subtotal_discount"]=!empty($cart->pricesUnformatted[$id]["subtotal_discount"])?$currency->priceDisplay($cart->pricesUnformatted[$id]["discountAmount"], 0, $cart->products[$id]->quantity):"";
$price_values["products"][$id]["subtotal_with_tax"] = "";
if (VmConfig::get('checkout_show_origprice',1) && !empty($cart->pricesUnformatted[$id]['basePriceWithTax']) && $cart->pricesUnformatted[$id]['basePriceWithTax'] != $cart->pricesUnformatted[$id]['salesPrice'] )
{
$old_baseprice = !empty($cart->pricesUnformatted[$id]["basePriceWithTax"])?$currency->priceDisplay($cart->pricesUnformatted[$id]["basePriceWithTax"], 0, $cart->products[$id]->quantity):"";
$price_values["products"][$id]["subtotal_with_tax"]='<span class="line-through">'.$old_baseprice.'</span><br />';
}
$price_values["products"][$id]["subtotal_with_tax"] .= !empty($cart->pricesUnformatted[$id]["subtotal_with_tax"])?$currency->priceDisplay($cart->pricesUnformatted[$id]["subtotal_with_tax"]):"";
$i++;
if(count($cart->products) == $i)
{
break;
}
continue;
}
//изменение стоимости на группу
$user = JFactory::getUser();
$rad_discount_sum=get_raddicount($user->id,$cart->pricesUnformatted["billTotal"]);
$cart->pricesUnformatted["billTotal"]=$cart->pricesUnformatted["billTotal"]*1-$rad_discount_sum;
$price_values["discountname"]=$_SESSION['rad_discount_name'];
$priceList = array("salesPrice","salesPriceShipment","paymentTax","shipmentTax","billTaxAmount","discountAmount","salesPriceCoupon","salesPricePayment","couponTax","taxAmount","billTotal","billDiscountAmount");
if(!empty($cart->couponCode)) $price_values["couponCode"]= $cart->couponCode;
foreach ($priceList as $price_name) {
if(!empty($cart->pricesUnformatted[$price_name])) $price_values[$price_name] = $currency->priceDisplay($cart->pricesUnformatted[$price_name]);
else $price_values[$price_name] = "";
}
$price_values["couponDescr"] = "";
$price_values["couponCode"] = "";
if(!empty($cart->cartData["couponCode"]))
$price_values["couponCode"] = $cart->cartData["couponCode"];
if(!empty($cart->cartData["couponDescr"]))
$price_values["couponDescr"] = $cart->cartData["couponDescr"];
$price_values["billTotalunformat"]= $cart->pricesUnformatted["billTotal"];
if(count($this->cart->cartData['taxRulesBill']) > 0)
{
$taxRulesBill = array();
foreach($this->cart->cartData['taxRulesBill'] as $rule)
{
$virtuemart_calc_id = $rule['virtuemart_calc_id'];
$calcname = $rule['calc_name'];
$taxRulesBill[$virtuemart_calc_id]["name"] = $calcname;
$taxRulesBill[$virtuemart_calc_id]["price"] = $this->currencyDisplay->createPriceDiv($rule['virtuemart_calc_id'].'Diff','', $this->cart->pricesUnformatted[$rule['virtuemart_calc_id'].'Diff'],true);
}
$price_values["taxRulesBill"] = $taxRulesBill;
}
if(count($this->cart->cartData['DATaxRulesBill']) > 0)
{
$DATaxRulesBill = array();
foreach($this->cart->cartData['DATaxRulesBill'] as $rule)
{
$virtuemart_calc_id = $rule['virtuemart_calc_id'];
$calcname = $rule['calc_name'];
$DATaxRulesBill[$virtuemart_calc_id]["name"] = $calcname;
$DATaxRulesBill[$virtuemart_calc_id]["price"] = $this->currencyDisplay->createPriceDiv($rule['virtuemart_calc_id'].'Diff','', $this->cart->pricesUnformatted[$rule['virtuemart_calc_id'].'Diff'],true);
}
$price_values["DATaxRulesBill"] = $DATaxRulesBill;
}
if(count($this->cart->cartData['DBTaxRulesBill']) > 0)
{
$DBTaxRulesBill = array();
foreach($this->cart->cartData['DBTaxRulesBill'] as $rule)
{
$virtuemart_calc_id = $rule['virtuemart_calc_id'];
$calcname = $rule['calc_name'];
$DBTaxRulesBill[$virtuemart_calc_id]["name"] = $calcname;
$DBTaxRulesBill[$virtuemart_calc_id]["price"] = $this->currencyDisplay->createPriceDiv($rule['virtuemart_calc_id'].'Diff','', $this->cart->pricesUnformatted[$rule['virtuemart_calc_id'].'Diff'],true);
}
$price_values["DBTaxRulesBill"] = $DBTaxRulesBill;
}echo json_encode($price_values);
exit;
?>
В файле шаблон цен нужно добаить элемент для вывода названия скидки
plugins/system/onepage_generic/cart/tmpl/default_price.php
<?php
if (isset($_SESSION['rad_discount_name'])) $disname=$_SESSION['rad_discount_name']; else $disname='';
?>
<div class="total opg-grid opg-text-right" id="bill_totalfulldiv">
<div class="price-type opg-width-large-3-4 opg-width-small-1-2 opg-width-1-2 opg-text-large opg-text-primary opg-text-bold"><?php echo JText::_('COM_VIRTUEMART_CART_TOTAL').': ' ?></div>
<div class="price-amount opg-width-large-1-4 opg-width-small-1-2 opg-width-1-2 opg-text-large opg-text-primary opg-text-bold" id="bill_total"><?php echo $this->currencyDisplay->createPriceDiv('billTotal','', $this->cart->pricesUnformatted['billTotal'],true); ?></div>
<div class="price-amount opg-width-large-3-4 opg-width-small-1-2 opg-width-1-2 opg-text-large opg-text-primary opg-text-bold" id="bill_total_discountname"><?php echo $disname; ?></div>
<div class="clear"></div>
</div>
Добавим вывод подписи при перерасчете чека - на форме должен быть элемент с тегом #bill_total_discountname
plugins/system/onepage_generic/onepage.js
if(data.billTotal != "")
{
jQuery("#bill_totalamountfulldiv").show();
jQuery("#bottom_total").show();
jQuery('#bill_total').html(data.billTotal);
jQuery('#bill_total_discountname').html(data.discountname);
jQuery('#carttotal').html(data.billTotal);
jQuery('#carttotalunformat').val(data.billTotalunformat);
}
else
{
jQuery("#bill_totalamountfulldiv").hide();
jQuery("#bottom_total").hide();
}
Далее нужно повторить скидку в момент создания заказа в базе
components/virtuemart/helper/cart.php
Вы можете получить доступ,купив эту доработку
Необходимо также в стандартном и всех остлальных плагинах оплаты выключить оповещение покупателя - потому что покупателю придет письмо без скидки.
/plugins/vmpayment/standard/standard.php
function plgVmConfirmedOrder ($cart, $order) {function plgVmConfirmedOrder ($cart, $order) {
if (!($method = $this->getVmPluginMethod ($order['details']['BT']->virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement ($method->payment_element)) { return FALSE; }
vmLanguage::loadJLang('com_virtuemart',true); vmLanguage::loadJLang('com_virtuemart_orders', TRUE);
$this->getPaymentCurrency($method, $order['details']['BT']->payment_currency_id); $currency_code_3 = shopFunctions::getCurrencyByID($method->payment_currency, 'currency_code_3'); $email_currency = $this->getEmailCurrency($method);
$totalInPaymentCurrency = vmPSPlugin::getAmountInCurrency($order['details']['BT']->order_total,$method->payment_currency);
if (!empty($method->payment_info)) { $lang = JFactory::getLanguage (); if ($lang->hasKey ($method->payment_info)) { $method->payment_info = vmText::_ ($method->payment_info); } }
$dbValues['payment_name'] = $this->renderPluginName ($method) . '<br />' . $method->payment_info; $dbValues['order_number'] = $order['details']['BT']->order_number; $dbValues['virtuemart_paymentmethod_id'] = $order['details']['BT']->virtuemart_paymentmethod_id; $dbValues['cost_per_transaction'] = $method->cost_per_transaction; $dbValues['cost_min_transaction'] = $method->cost_min_transaction; $dbValues['cost_percent_total'] = $method->cost_percent_total; $dbValues['payment_currency'] = $currency_code_3; $dbValues['email_currency'] = $email_currency; $dbValues['payment_order_total'] = $totalInPaymentCurrency['value']; $dbValues['tax_id'] = $method->tax_id; //вставляем скидку if (isset($_SESSION['rad_dicount_total']) and $_SESSION['rad_dicount_total']*1>0) { $rad_discount_sum=$_SESSION['rad_dicount_total']*1; $order['details']['BT']->order_total=$order['details']['BT']->order_total*1-$rad_discount_sum*1; $order['details']['BT']->order_salesPrice=$order['details']['BT']->order_salesPrice*1-$rad_discount_sum*1; $order['details']['BT']->order_subtotal=$order['details']['BT']->order_subtotal*1-$rad_discount_sum*1; $order['details']['BT']->order_billDiscountAmount=$order['details']['BT']->order_billDiscountAmount*1+$rad_discount_sum*1; $order['details']['BT']->order_discountAmount=$order['details']['BT']->order_discountAmount*1+$rad_discount_sum*1; $_SESSION['rad_dicount_total']=''; $_SESSION['rad_dicount_name']=''; } $this->storePSPluginInternalData ($dbValues);
$currency = CurrencyDisplay::getInstance ('', $order['details']['BT']->virtuemart_vendor_id);
$modelOrder = VmModel::getModel ('orders');
$order['order_status'] = $this->getNewStatus ($method);
$order['customer_notified'] = 0;
$order['comments'] = '';
$modelOrder->updateStatusForOneOrder ($order['details']['BT']->virtuemart_order_id, $order, TRUE);
$orderlink=''; $tracking = VmConfig::get('ordertracking','guests'); if($tracking !='none' and !($tracking =='registered' and empty($order['details']['BT']->virtuemart_user_id) )) {
$orderlink = 'index.php?option=com_virtuemart&view=orders&layout=details&order_number=' . $order['details']['BT']->order_number; if ($tracking == 'guestlink' or ($tracking == 'guests' and empty($order['details']['BT']->virtuemart_user_id))) { $orderlink .= '&order_pass=' . $order['details']['BT']->order_pass; } }
$html = $this->renderByLayout('post_payment', array( 'order_number' =>$order['details']['BT']->order_number, 'order_pass' =>$order['details']['BT']->order_pass, 'payment_name' => $dbValues['payment_name'], 'displayTotalInPaymentCurrency' => $totalInPaymentCurrency['display'], 'orderlink' =>$orderlink ));
//We delete the old stuff $cart->emptyCart (); vRequest::setVar ('html', $html); return TRUE; }