public function postExecute($order_id = null, $result = null) { $data = parent::postExecute($order_id, $result); if ($order_id != null) { $log_model = new waLogModel(); $log_model->add('order_restore', $order_id); $order_model = new shopOrderModel(); $app_settings_model = new waAppSettingsModel(); if ($this->state_id != 'refunded') { // for logging changes in stocks shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_ORDER, 'Order %s was restored', array('order_id' => $order_id)); $update_on_create = $app_settings_model->get('shop', 'update_stock_count_on_create_order'); if ($update_on_create) { $order_model->reduceProductsFromStocks($order_id); } else { if (!$update_on_create && $this->state_id != 'new') { $order_model->reduceProductsFromStocks($order_id); } } shopProductStocksLogModel::clearContext(); } $order = $order_model->getById($order_id); if ($order && $order['paid_date']) { shopAffiliate::applyBonus($order_id); shopCustomers::recalculateTotalSpent($order['contact_id']); } } return $data; }
public function execute() { if (!shopAffiliate::isEnabled()) { throw new waException(_w('Unknown page'), 404); } $scm = new shopCustomerModel(); $customer = $scm->getById(wa()->getUser()->getId()); $atm = new shopAffiliateTransactionModel(); $affiliate_history = $atm->getByContact(wa()->getUser()->getId()); $url_tmpl = wa()->getRouteUrl('/frontend/myOrder', array('id' => '%ID%')); foreach ($affiliate_history as &$row) { if ($row['order_contact_id'] == $row['contact_id']) { $row['order_url'] = str_replace('%ID%', $row['order_id'], $url_tmpl); } } $this->view->assign('customer', $customer); $this->view->assign('affiliate_history', $affiliate_history); // Set up layout and template from theme $this->setThemeTemplate('my.affiliate.html'); $this->view->assign('my_nav_selected', 'affiliate'); if (!waRequest::isXMLHttpRequest()) { $this->setLayout(new shopFrontendLayout()); $this->getResponse()->setTitle(_w('Affiliate program')); $this->view->assign('breadcrumbs', self::getBreadcrumbs()); $this->layout->assign('nofollow', true); } /** * * @event frontend_my_affiliate * @return array[string]string $return[%plugin_id%] html output */ $this->view->assign('frontend_my_affiliate', wa()->event('frontend_my_affiliate')); }
public function execute($params = null) { $result = array(); // from payment callback if (is_array($params)) { $order_id = $params['order_id']; $result['text'] = $params['plugin'] . ' (' . $params['view_data'] . ' - ' . $params['amount'] . ' ' . $params['currency_id'] . ')'; $result['update']['params'] = array('payment_transaction_id' => $params['id']); } else { $order_id = $params; $result['text'] = waRequest::post('text', ''); } $order_model = new shopOrderModel(); $order = $order_model->getById($order_id); $log_model = new waLogModel(); if (wa()->getEnv() == 'backend') { $log_model->add('order_pay', $order_id); } else { $log_model->add('order_pay_callback', $order_id, $order['contact_id']); } if (!$order['paid_year']) { shopAffiliate::applyBonus($order_id); if (wa('shop')->getConfig()->getOption('order_paid_date') == 'create') { $time = strtotime($order['create_datetime']); } else { $time = time(); } $result['update'] = array('paid_year' => date('Y', $time), 'paid_quarter' => floor((date('n', $time) - 1) / 3) + 1, 'paid_month' => date('n', $time), 'paid_date' => date('Y-m-d', $time)); if (!$order_model->where("contact_id = ? AND paid_date IS NOT NULL", $order['contact_id'])->limit(1)->fetch()) { $result['update']['is_first'] = 1; } } return $result; }
public function execute($order_id = null) { $om = new shopOrderModel(); $order = $om->getById($order_id); if ($order['paid_year']) { shopAffiliate::cancelBonus($order_id); } return true; }
/** * Returns aggregate discount amount applicable to order. * * @param array $order Order data array * @param bool $apply Whether discount-related information must be added to order parameters (where appropriate) * @return float Total discount value expressed in order currency */ public static function calculate(&$order, $apply = false) { $currency = isset($order['currency']) ? $order['currency'] : wa('shop')->getConfig()->getCurrency(false); $applicable_discounts = array(); $contact = self::getContact($order); // Discount by contact category applicable? if (self::isEnabled('category')) { $applicable_discounts[] = self::byCategory($order, $contact, $apply); } // Discount by coupon applicable? if (self::isEnabled('coupons')) { $applicable_discounts[] = self::byCoupons($order, $contact, $apply); } // Discount by order total applicable? if (self::isEnabled('order_total')) { $crm = new shopCurrencyModel(); $dbsm = new shopDiscountBySumModel(); // Order total in default currency $order_total = (double) $crm->convert($order['total'], $currency, wa('shop')->getConfig()->getCurrency()); $applicable_discounts[] = max(0.0, min(100.0, (double) $dbsm->getDiscount('order_total', $order_total))) * $order['total'] / 100.0; } // Discount by customer total spent applicable? if (self::isEnabled('customer_total')) { $applicable_discounts[] = self::byCustomerTotal($order, $contact, $apply); } /** * @event order_calculate_discount * @param array $params * @param array[string] $params['order'] order info array('total' => '', 'items' => array(...)) * @param array[string] $params['contact'] contact info * @param array[string] $params['apply'] calculate or apply discount * @return float discount */ $event_params = array('order' => &$order, 'contact' => $contact, 'apply' => $apply); $plugins_discounts = wa('shop')->event('order_calculate_discount', $event_params); foreach ($plugins_discounts as $plugin_discount) { $applicable_discounts[] = $plugin_discount; } // Select max discount or sum depending on global setting. $discount = 0.0; if ($applicable_discounts = array_filter($applicable_discounts, 'is_numeric')) { if (wa('shop')->getSetting('discounts_combine') == 'sum') { $discount = (double) array_sum($applicable_discounts); } else { $discount = (double) max($applicable_discounts); } } // Discount based on affiliate bonus? if (shopAffiliate::isEnabled()) { $discount = $discount + (double) shopAffiliate::discount($order, $contact, $apply, $discount); } return min(max(0, $discount), ifset($order['total'], 0)); }
public function execute() { $asm = new waAppSettingsModel(); if (waRequest::post()) { $conf = waRequest::post('conf'); if ($conf && is_array($conf)) { $conf['affiliate_credit_rate'] = str_replace(',', '.', (double) str_replace(',', '.', ifset($conf['affiliate_credit_rate'], '0'))); $conf['affiliate_usage_rate'] = str_replace(',', '.', (double) str_replace(',', '.', ifset($conf['affiliate_usage_rate'], '0'))); foreach ($conf as $k => $v) { $asm->set('shop', $k, $v); } } } $enabled = shopAffiliate::isEnabled(); $def_cur = waCurrency::getInfo(wa()->getConfig()->getCurrency()); $tm = new shopTypeModel(); $product_types = $tm->getAll(); $conf = $asm->get('shop'); if (!empty($conf['affiliate_product_types'])) { $conf['affiliate_product_types'] = array_fill_keys(explode(',', $conf['affiliate_product_types']), true); } else { $conf['affiliate_product_types'] = array(); } $this->view->assign('conf', $conf); $this->view->assign('enabled', $enabled); $this->view->assign('product_types', $product_types); $this->view->assign('def_cur_sym', ifset($def_cur['sign'], wa()->getConfig()->getCurrency())); /** * Backend affiliate settings * * Plugins are expected to return one item or a list of items to to add to affiliate menu. * Each item is represented by an array: * array( * 'id' => string, // Required. * 'name' => string, // Required. * 'url' => string, // Required (unless you hack into JS using 'html' parameter). Content for settings page is fetched from this URL. * ) * * @event backend_settings_discounts */ $plugins = wa()->event('backend_settings_affiliate'); $config = wa('shop')->getConfig(); foreach ($plugins as $k => &$p) { if (substr($k, -7) == '-plugin') { $plugin_id = substr($k, 0, -7); $plugin_info = $config->getPluginInfo($plugin_id); $p['img'] = $plugin_info['img']; } } $this->view->assign('plugins', $plugins); $this->view->assign('installer', $this->getUser()->getRights('installer', 'backend')); }
public function execute($order_id = null) { $order_model = new shopOrderModel(); $order = $order_model->getById($order_id); if ($order['paid_year']) { return true; } else { if (wa('shop')->getConfig()->getOption('order_paid_date') == 'create') { $time = strtotime($order['create_datetime']); } else { $time = time(); } shopAffiliate::applyBonus($order_id); $result = array('update' => array('paid_year' => date('Y', $time), 'paid_quarter' => floor((date('n', $time) - 1) / 3) + 1, 'paid_month' => date('n', $time), 'paid_date' => date('Y-m-d', $time))); if (!$order_model->where("contact_id = ? AND paid_date IS NOT NULL", $order['contact_id'])->limit(1)->fetch()) { $result['update']['is_first'] = 1; } return $result; } }
public function execute() { $cart = new shopCart(); $item_id = waRequest::post('id'); $cart_items_model = new shopCartItemsModel(); $item = $cart_items_model->getById($item_id); $is_html = waRequest::request('html'); if ($q = waRequest::post('quantity', 0, 'int')) { if (!wa()->getSetting('ignore_stock_count')) { if ($item['type'] == 'product') { $product_model = new shopProductModel(); $p = $product_model->getById($item['product_id']); $sku_model = new shopProductSkusModel(); $sku = $sku_model->getById($item['sku_id']); // check quantity if ($sku['count'] !== null && $q > $sku['count']) { $q = $sku['count']; $name = $p['name'] . ($sku['name'] ? ' (' . $sku['name'] . ')' : ''); $this->response['error'] = sprintf(_w('Only %d pcs of %s are available, and you already have all of them in your shopping cart.'), $q, $name); $this->response['q'] = $q; } } } $cart->setQuantity($item_id, $q); $this->response['item_total'] = $is_html ? shop_currency_html($cart->getItemTotal($item_id), true) : shop_currency($cart->getItemTotal($item_id), true); } elseif ($v = waRequest::post('service_variant_id')) { $cart->setServiceVariantId($item_id, $v); $this->response['item_total'] = $is_html ? shop_currency_html($cart->getItemTotal($item['parent_id']), true) : shop_currency($cart->getItemTotal($item['parent_id']), true); } $total = $cart->total(); $discount = $cart->discount(); $this->response['total'] = $is_html ? shop_currency_html($total, true) : shop_currency($total, true); $this->response['discount'] = $is_html ? shop_currency_html($discount, true) : shop_currency($discount, true); $this->response['discount_numeric'] = $discount; $this->response['count'] = $cart->count(); if (shopAffiliate::isEnabled()) { $add_affiliate_bonus = shopAffiliate::calculateBonus(array('total' => $total, 'discount' => $discount, 'items' => $cart->items(false))); $this->response['add_affiliate_bonus'] = sprintf(_w("This order will add +%s points to your affiliate bonus."), round($add_affiliate_bonus, 2)); } }
public function execute() { $id = waRequest::post('id'); $cart = new shopCart(); $is_html = waRequest::request('html'); if ($id) { $item = $cart->deleteItem($id); if ($item && !empty($item['parent_id'])) { $item_total = $cart->getItemTotal($item['parent_id']); $this->response['item_total'] = $is_html ? shop_currency_html($item_total, true) : shop_currency($item_total, true); } } $total = $cart->total(); $discount = $cart->discount(); $this->response['total'] = $is_html ? shop_currency_html($total, true) : shop_currency($total, true); $this->response['discount'] = $is_html ? shop_currency_html($discount, true) : shop_currency($discount, true); $this->response['count'] = $cart->count(); if (shopAffiliate::isEnabled()) { $add_affiliate_bonus = shopAffiliate::calculateBonus(array('total' => $total, 'discount' => $discount, 'items' => $cart->items(false))); $this->response['add_affiliate_bonus'] = sprintf(_w("This order will add +%s points to your affiliate bonus."), round($add_affiliate_bonus, 2)); } }
public function postExecute($order_id = null, $result = null) { $data = parent::postExecute($order_id, $result); $order_model = new shopOrderModel(); if (is_array($order_id)) { $order = $order_id; $order_id = $order['id']; } else { $order = $order_model->getById($order_id); } shopCustomers::recalculateTotalSpent($order['contact_id']); if ($order_id != null) { $log_model = new waLogModel(); $log_model->add('order_refund', $order_id); $order_model = new shopOrderModel(); $order_model->updateById($order_id, array('paid_date' => null, 'paid_year' => null, 'paid_month' => null, 'paid_quarter' => null)); // for logging changes in stocks shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_ORDER, 'Order %s was refunded', array('order_id' => $order_id)); $order_model->returnProductsToStocks($order_id); shopAffiliate::cancelBonus($order_id); $order_model->recalculateProductsTotalSales($order_id); } return $data; }
public function cart() { $this->getResponse()->addHeader("Cache-Control", "no-store, no-cache, must-revalidate"); $this->getResponse()->addHeader("Expires", date("r")); if (waRequest::method() == 'post') { $data = wa()->getStorage()->get('shop/checkout', array()); if ($coupon_code = waRequest::post('coupon_code')) { $data['coupon_code'] = $coupon_code; } elseif (isset($data['coupon_code'])) { unset($data['coupon_code']); } if (($use = waRequest::post('use_affiliate')) !== null) { if ($use) { $data['use_affiliate'] = 1; } elseif (isset($data['use_affiliate'])) { unset($data['use_affiliate']); } } if ($coupon_code || $use) { wa()->getStorage()->set('shop/checkout', $data); wa()->getStorage()->remove('shop/cart'); } } $cart_model = new shopCartItemsModel(); $cart = new shopCart(); $code = $cart->getCode(); $errors = array(); if (waRequest::post('checkout')) { $saved_quantity = $cart_model->select('id,quantity')->where("type='product' AND code = s:code", array('code' => $code))->fetchAll('id'); $quantity = waRequest::post('quantity'); foreach ($quantity as $id => $q) { if ($q != $saved_quantity[$id]) { $cart->setQuantity($id, $q); } } $not_available_items = $cart_model->getNotAvailableProducts($code, !wa()->getSetting('ignore_stock_count')); foreach ($not_available_items as $row) { if ($row['sku_name']) { $row['name'] .= ' (' . $row['sku_name'] . ')'; } if ($row['available']) { $errors[$row['id']] = sprintf(_w('Only %d pcs of %s are available, and you already have all of them in your shopping cart.'), $row['count'], $row['name']); } else { $errors[$row['id']] = _w('Oops! %s is not available for purchase at the moment. Please remove this product from your shopping cart to proceed.'); } } if (!$errors) { $this->redirect(wa()->getRouteUrl('/frontend/checkout')); } } $items = $cart_model->where('code= ?', $code)->order('parent_id')->fetchAll('id'); $product_ids = $sku_ids = $service_ids = $type_ids = array(); foreach ($items as $item) { $product_ids[] = $item['product_id']; $sku_ids[] = $item['sku_id']; } $product_ids = array_unique($product_ids); $sku_ids = array_unique($sku_ids); $product_model = new shopProductModel(); if (waRequest::param('url_type') == 2) { $products = $product_model->getWithCategoryUrl($product_ids); } else { $products = $product_model->getById($product_ids); } $sku_model = new shopProductSkusModel(); $skus = $sku_model->getByField('id', $sku_ids, 'id'); $image_model = new shopProductImagesModel(); $delete_items = array(); foreach ($items as $item_id => &$item) { if (!isset($skus[$item['sku_id']])) { unset($items[$item_id]); $delete_items[] = $item_id; continue; } if ($item['type'] == 'product') { $item['product'] = $products[$item['product_id']]; $sku = $skus[$item['sku_id']]; if ($sku['image_id'] && $sku['image_id'] != $item['product']['image_id']) { $img = $image_model->getById($sku['image_id']); if ($img) { $item['product']['image_id'] = $sku['image_id']; $item['product']['ext'] = $img['ext']; } } $item['sku_name'] = $sku['name']; $item['sku_code'] = $sku['sku']; $item['price'] = $sku['price']; $item['compare_price'] = $sku['compare_price']; $item['currency'] = $item['product']['currency']; $type_ids[] = $item['product']['type_id']; if (isset($errors[$item_id])) { $item['error'] = $errors[$item_id]; if (strpos($item['error'], '%s') !== false) { $item['error'] = sprintf($item['error'], $item['product']['name'] . ($item['sku_name'] ? ' (' . $item['sku_name'] . ')' : '')); } } } } unset($item); if ($delete_items) { $cart_model->deleteByField(array('code' => $code, 'id' => $delete_items)); } $type_ids = array_unique($type_ids); // get available services for all types of products $type_services_model = new shopTypeServicesModel(); $rows = $type_services_model->getByField('type_id', $type_ids, true); $type_services = array(); foreach ($rows as $row) { $service_ids[] = $row['service_id']; $type_services[$row['type_id']][$row['service_id']] = true; } // get services for all products $product_services_model = new shopProductServicesModel(); $rows = $product_services_model->getByProducts($product_ids); $product_services = $sku_services = array(); foreach ($rows as $row) { if ($row['sku_id'] && !in_array($row['sku_id'], $sku_ids)) { continue; } $service_ids[] = $row['service_id']; if (!$row['sku_id']) { $product_services[$row['product_id']][$row['service_id']]['variants'][$row['service_variant_id']] = $row; } if ($row['sku_id']) { $sku_services[$row['sku_id']][$row['service_id']]['variants'][$row['service_variant_id']] = $row; } } $service_ids = array_unique($service_ids); $service_model = new shopServiceModel(); $variant_model = new shopServiceVariantsModel(); $services = $service_model->getByField('id', $service_ids, 'id'); foreach ($services as &$s) { unset($s['id']); } unset($s); $rows = $variant_model->getByField('service_id', $service_ids, true); foreach ($rows as $row) { $services[$row['service_id']]['variants'][$row['id']] = $row; unset($services[$row['service_id']]['variants'][$row['id']]['id']); } foreach ($items as $item_id => $item) { if ($item['type'] == 'product') { $p = $item['product']; $item_services = array(); // services from type settings if (isset($type_services[$p['type_id']])) { foreach ($type_services[$p['type_id']] as $service_id => &$s) { $item_services[$service_id] = $services[$service_id]; } } // services from product settings if (isset($product_services[$item['product_id']])) { foreach ($product_services[$item['product_id']] as $service_id => $s) { if (!isset($s['status']) || $s['status']) { if (!isset($item_services[$service_id])) { $item_services[$service_id] = $services[$service_id]; } // update variants foreach ($s['variants'] as $variant_id => $v) { if ($v['status']) { if ($v['price'] !== null) { $item_services[$service_id]['variants'][$variant_id]['price'] = $v['price']; } } else { unset($item_services[$service_id]['variants'][$variant_id]); } } } elseif (isset($item_services[$service_id])) { // remove disabled service unset($item_services[$service_id]); } } } // services from sku settings if (isset($sku_services[$item['sku_id']])) { foreach ($sku_services[$item['sku_id']] as $service_id => $s) { if (!isset($s['status']) || $s['status']) { // update variants foreach ($s['variants'] as $variant_id => $v) { if ($v['status']) { if ($v['price'] !== null) { $item_services[$service_id]['variants'][$variant_id]['price'] = $v['price']; } } else { unset($item_services[$service_id]['variants'][$variant_id]); } } } elseif (isset($item_services[$service_id])) { // remove disabled service unset($item_services[$service_id]); } } } foreach ($item_services as $s_id => &$s) { if (!$s['variants']) { unset($item_services[$s_id]); continue; } if ($s['currency'] == '%') { foreach ($s['variants'] as $v_id => $v) { $s['variants'][$v_id]['price'] = $v['price'] * $item['price'] / 100; } $s['currency'] = $item['currency']; } if (count($s['variants']) == 1) { $v = reset($s['variants']); $s['price'] = $v['price']; unset($s['variants']); } } unset($s); uasort($item_services, array('shopServiceModel', 'sortServices')); $items[$item_id]['services'] = $item_services; } else { $items[$item['parent_id']]['services'][$item['service_id']]['id'] = $item['id']; if (isset($item['service_variant_id'])) { $items[$item['parent_id']]['services'][$item['service_id']]['variant_id'] = $item['service_variant_id']; } unset($items[$item_id]); } } foreach ($items as $item_id => $item) { $price = shop_currency($item['price'] * $item['quantity'], $item['currency'], null, false); if (isset($item['services'])) { foreach ($item['services'] as $s) { if (!empty($s['id'])) { if (isset($s['variants'])) { $price += shop_currency($s['variants'][$s['variant_id']]['price'] * $item['quantity'], $s['currency'], null, false); } else { $price += shop_currency($s['price'] * $item['quantity'], $s['currency'], null, false); } } } } $items[$item_id]['full_price'] = $price; } $total = $cart->total(false); $order = array('total' => $total, 'items' => $items); $order['discount'] = $discount = shopDiscounts::calculate($order); $order['total'] = $total = $total - $order['discount']; $data = wa()->getStorage()->get('shop/checkout'); $this->view->assign('cart', array('items' => $items, 'total' => $total, 'count' => $cart->count())); $this->view->assign('coupon_code', isset($data['coupon_code']) ? $data['coupon_code'] : ''); if (shopAffiliate::isEnabled()) { $affiliate_bonus = 0; if ($this->getUser()->isAuth()) { $customer_model = new shopCustomerModel(); $customer = $customer_model->getById($this->getUser()->getId()); $affiliate_bonus = $customer ? round($customer['affiliate_bonus'], 2) : 0; } $this->view->assign('affiliate_bonus', $affiliate_bonus); $use = !empty($data['use_affiliate']); $this->view->assign('use_affiliate', $use); if ($use) { $discount -= shop_currency(shopAffiliate::convertBonus($order['params']['affiliate_bonus']), $this->getConfig()->getCurrency(true), null, false); $this->view->assign('used_affiliate_bonus', $order['params']['affiliate_bonus']); } $order['currency'] = $this->getConfig()->getCurrency(false); $add_affiliate_bonus = shopAffiliate::calculateBonus($order); $this->view->assign('add_affiliate_bonus', round($add_affiliate_bonus, 2)); } $this->view->assign('discount', $discount); /** * @event frontend_cart * @return array[string]string $return[%plugin_id%] html output */ $this->view->assign('frontend_cart', wa()->event('frontend_cart')); $checkout_flow = new shopCheckoutFlowModel(); $checkout_flow->add(array('code' => $code, 'step' => 0, 'description' => null)); }
/** * @param $data */ protected function addService($data) { $item = $this->cart_model->getById($data['parent_id']); if (!$item) { $this->errors = _w('Error'); return; } unset($item['id']); $item['parent_id'] = $data['parent_id']; $item['type'] = 'service'; $item['service_id'] = $data['service_id']; if (isset($data['service_variant_id'])) { $item['service_variant_id'] = $data['service_variant_id']; } else { $service_model = new shopServiceModel(); $service = $service_model->getById($data['service_id']); $item['service_variant_id'] = $service['variant_id']; } $id = $this->cart->addItem($item); $total = $this->cart->total(); $discount = $this->cart->discount(); $this->response['id'] = $id; $this->response['total'] = $this->currencyFormat($total); $this->response['count'] = $this->cart->count(); $this->response['discount'] = $this->currencyFormat($discount); $item_total = $this->cart->getItemTotal($data['parent_id']); $this->response['item_total'] = $this->currencyFormat($item_total); if (shopAffiliate::isEnabled()) { $add_affiliate_bonus = shopAffiliate::calculateBonus(array('total' => $total, 'discount' => $discount, 'items' => $this->cart->items(false))); $this->response['add_affiliate_bonus'] = sprintf(_w("This order will add +%s points to your affiliate bonus."), round($add_affiliate_bonus, 2)); } }
<?php $order_model = new shopOrderModel(); $sql = "SELECT * FROM shop_order WHERE state_id = 'deleted' AND paid_date IS NOT NULL"; foreach ($order_model->query($sql) as $order) { $order_id = $order['id']; shopCustomers::recalculateTotalSpent($order['contact_id']); $order_model->updateById($order_id, array('paid_date' => null, 'paid_year' => null, 'paid_month' => null, 'paid_quarter' => null)); $order_model->returnProductsToStocks($order_id); shopAffiliate::cancelBonus($order_id); $order_model->recalculateProductsTotalSales($order_id); }
public static function getAffiliateDiscount($affiliate_bonus, $order) { $data = wa()->getStorage()->get('shop/checkout'); $use = !empty($data['use_affiliate']); $usage_percent = (double) wa()->getSetting('affiliate_usage_percent', 0, 'shop'); if (!$usage_percent) { $usage_percent = 100; } $affiliate_discount = 0; if ($use) { $affiliate_discount = shop_currency(shopAffiliate::convertBonus($order['params']['affiliate_bonus']), wa('shop')->getConfig()->getCurrency(true), null, false); if ($usage_percent) { $affiliate_discount = min($affiliate_discount, ($order['total'] + $affiliate_discount) * $usage_percent / 100.0); } } elseif ($affiliate_bonus) { $affiliate_discount = shop_currency(shopAffiliate::convertBonus($affiliate_bonus), wa('shop')->getConfig()->getCurrency(true), null, false); if ($usage_percent) { $affiliate_discount = min($affiliate_discount, $order['total'] * $usage_percent / 100.0); } } return $affiliate_discount; }