protected static function getCoreTypes()
 {
     $core_types = array(array('id' => 'coupons', 'name' => _w('Coupons'), 'url' => '?module=settings&action=discountsCoupons'), array('id' => 'category', 'name' => _w('By contact category'), 'url' => '?module=settings&action=discountsCategory'), array('id' => 'order_total', 'name' => _w('By order total'), 'url' => '?module=settings&action=discountsOrderTotal'), array('id' => 'customer_total', 'name' => _w('By customers overall purchases'), 'url' => '?module=settings&action=discountsCustomerTotal'));
     $result = array();
     foreach ($core_types as $d) {
         $d['status'] = shopDiscounts::isEnabled($d['id']);
         $result[$d['id']] = $d;
     }
     return $result;
 }
 public function execute()
 {
     $ccdm = new shopContactCategoryDiscountModel();
     if (waRequest::post()) {
         $categories = waRequest::post('categories', array());
         if (is_array($categories)) {
             $ccdm->save($categories);
         }
     }
     // Categories
     $categories = array();
     $ccm = new waContactCategoryModel();
     $values = $ccdm->getAll('category_id', true);
     foreach ($ccm->getAll('id') as $c) {
         if ($c['app_id'] == 'shop') {
             $c['value'] = (double) ifset($values[$c['id']], 0);
             $categories[$c['id']] = $c;
         }
     }
     $enabled = shopDiscounts::isEnabled('category');
     $this->view->assign('enabled', $enabled);
     $this->view->assign('categories', $categories);
 }
 public function execByType($type)
 {
     $dbsm = new shopDiscountBySumModel();
     if (waRequest::post()) {
         $sums = waRequest::post('rate_sum');
         $discounts = waRequest::post('rate_discount');
         $rows = array();
         $dbsm->deleteByField('type', $type);
         if (is_array($sums) && is_array($discounts)) {
             foreach ($sums as $k => $sum) {
                 $sum = str_replace(',', '.', $sum);
                 if (!is_numeric($sum) || $sum < 0) {
                     continue;
                 }
                 $discount = (double) str_replace(',', '.', ifset($discounts[$k], 0));
                 $discount = min(max($discount, 0), 100);
                 if ($sum || $discount) {
                     $rows[] = array('sum' => $sum, 'discount' => $discount, 'type' => $type);
                 }
             }
             if ($rows) {
                 $dbsm->multipleInsert($rows);
             }
         }
     }
     $enabled = shopDiscounts::isEnabled($type);
     $def_cur = waCurrency::getInfo(wa()->getConfig()->getCurrency());
     $rates = $dbsm->getByType($type);
     foreach ($rates as &$r) {
         $r['sum'] = (double) $r['sum'];
         $r['discount'] = (double) $r['discount'];
     }
     $this->view->assign('rates', $rates);
     $this->view->assign('enabled', $enabled);
     $this->view->assign('def_cur_sym', ifset($def_cur['sign'], wa()->getConfig()->getCurrency()));
 }
 public function execute()
 {
     $enabled = shopDiscounts::isEnabled('coupons');
     $this->view->assign('enabled', $enabled);
 }