Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. <?php
  2. /*
  3. @author nikifalex
  4. @skype logoffice1
  5. @link http://opencartmodules.ru
  6. */
  7.  
  8.  
  9. class ModelExtensionTotalDiscountsTotal extends Model {
  10.  
  11. public function getTotal($total) {
  12. if (!$this->config->get('discounts_total_status')) {
  13. return;
  14. }
  15.  
  16. $discounts_table=$this->config->get('discounts_total_discounts_table');
  17. if (!is_array($discounts_table)) {
  18. return;
  19. }
  20.  
  21. $last_days=$this->config->get('discounts_total_last_days');
  22. if ($last_days=='')
  23. $last_days=0;
  24.  
  25. if ($this->customer->isLogged()) {
  26. $this->language->load('extension/total/discounts_total');
  27.  
  28. if (isset($this->session->data['order_id']))
  29. $order_id = $this->session->data['order_id'];
  30. else
  31. $order_id = '';
  32. $total_orders = $this->getOrdersTotal($order_id,$last_days);
  33. if ($total_orders == '')
  34. $total_orders = 0;
  35.  
  36.  
  37. usort($discounts_table, array('ModelExtensionTotalDiscountsTotal', 'cmpd'));
  38.  
  39.  
  40.  
  41. $discount=0;
  42. foreach ($discounts_table as $d) {
  43. if ($total_orders>=$d['summ'])
  44. $discount=$d['value'];
  45. }
  46.  
  47. $discounts_total_calc_type_id=$this->config->get('discounts_total_calc_type_id');
  48. if ($discounts_total_calc_type_id==0) {
  49. $discount_total=$total*($discount/100);
  50. } elseif (in_array($discounts_total_calc_type_id,array(1,2))) {
  51. $products=$this->cart->getProducts();
  52. $discount_total=0;
  53. $this->load->model('catalog/product');
  54. foreach ($products as $product) {
  55. if ($discounts_total_calc_type_id==1) {
  56. $productb=$this->model_catalog_product->getProduct($product['product_id']);
  57. $productd=$this->model_catalog_product->getProductDiscounts($product['product_id']);
  58. if (!$productb['special'] && count($productd)==0) {
  59. $discount_total += $product['total'] * ($discount / 100);
  60. }
  61. }
  62. if ($discounts_total_calc_type_id==2) {
  63. $discount_total += $product['total'] * ($discount / 100);
  64. }
  65. }
  66. } else {
  67. $discount_total=0;
  68. }
  69.  
  70. //Проверка на наличие купона
  71. if ($this->session->data['coupon'] ) {
  72. $discount_total = 0;
  73. }
  74. $customer_group_info = $this->customer->getGroupId();
  75. //Проверка группы клиента
  76. if($customer_group_info != '4' ){
  77. $discount_total = 0;
  78. }
  79.  
  80.  
  81. if ($discount_total > 0) {
  82.  
  83. $total['totals'][] = array(
  84. 'code' => 'discounts_total',
  85. 'title' => $this->language->get('text_title').' '.$discount.'%',
  86. 'value' => -$discount_total,
  87. 'sort_order' => $this->config->get('discounts_total_sort_order')
  88. );
  89.  
  90. $total['total'] -= $discount_total;
  91. }
  92. }
  93. }
  94.  
  95. public function getOrdersTotal($order_id='',$last_days) {
  96.  
  97. $status=$this->config->get('discounts_total_order_status_id');
  98. if ((int)$last_days>0) {
  99. $sql = "SELECT sum(o.total) total FROM `" . DB_PREFIX . "order` o WHERE o.date_added >= NOW() - INTERVAL " . (int)$last_days . " DAY AND o.customer_id = '" . (int)$this->customer->getId() . "' AND o.order_status_id = '" . (int)$status . "' ";
  100. }
  101. else {
  102. $sql = "SELECT sum(o.total) total FROM `" . DB_PREFIX . "order` o WHERE o.customer_id = '" . (int)$this->customer->getId() . "' AND o.order_status_id = '" . (int)$status . "' ";
  103. }
  104.  
  105. if ($order_id!='')
  106. $sql.=" AND o.order_id<>'".$order_id."'";
  107.  
  108. $query = $this->db->query($sql);
  109. return $query->row['total'];
  110. }
  111.  
  112. private static function cmpd($a, $b)
  113. {
  114. if ($a["summ"]==$b["summ"]) {
  115. return 0;
  116. }
  117. return ($a["summ"]<$b["summ"]) ? -1 : 1;
  118. }
  119.  
  120.  
  121. }
  122.  
  123. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement