Guest User

Untitled

a guest
Jul 21st, 2020
20
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 3.0.8.0
  8. * @ Author : DeZender
  9. * @ Release on : 25.09.2017
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class ModelSaleOrderpro
  15. {
  16. public function getCopyOrder($order_id)
  17. {
  18. $new_order_id = 0;
  19.  
  20. if ($this->checkLicense( )) {
  21. $order_info = $this->getOrder( $order_id );
  22.  
  23. if ($order_info) {
  24. $custom_field = '';
  25. $payment_custom_field = '';
  26. $shipping_custom_field = '';
  27.  
  28. if (isset( $order_info['custom_field'] )) {
  29. $custom_field = json_encode( $order_info['custom_field'] );
  30. }
  31.  
  32. if (isset( $order_info['payment_custom_field'] )) {
  33. $payment_custom_field = json_encode( $order_info['payment_custom_field'] );
  34. }
  35.  
  36. if (isset( $order_info['shipping_custom_field'] )) {
  37. $shipping_custom_field = json_encode( $order_info['shipping_custom_field'] );
  38. }
  39.  
  40. $invoice_no = $this->getInvoiceNo( );
  41. $this->load->model( 'localisation/currency' );
  42.  
  43. if (!(empty( $order_info['currency_code'] ))) {
  44. $currency_info = $this->model_localisation_currency->getCurrencyByCode( $order_info['currency_code'] );
  45. }
  46. else {
  47. $currency_info = $this->model_localisation_currency->getCurrencyByCode( $this->config->get( 'config_currency' ) );
  48. }
  49.  
  50. $currency_id = ((!(empty( $currency_info['currency_id'] )) ? $currency_info['currency_id'] : 0));
  51. $currency_code = ((!(empty( $currency_info['code'] )) ? $currency_info['code'] : $this->config->get( 'config_currency' )));
  52. $currency_value = ((!(empty( $currency_info['value'] )) ? $currency_info['value'] : 1));
  53. $date_added = date( 'Y-m-d H:i:s', time( ) );
  54. $date_modified = date( 'Y-m-d H:i:s', time( ) );
  55. $osql = 'INSERT INTO `' . DB_PREFIX . 'order` SET shipping_address_format = \'' . $this->db->escape( $order_info['shipping_address_format'] ) . '\', payment_address_format = \'' . $this->db->escape( $order_info['payment_address_format'] ) . '\',';
  56. $osql .= ' invoice_prefix = \'' . $this->db->escape( $order_info['invoice_prefix'] ) . '\', ' . "\n\t\t\t\t\t" . 'invoice_no = \'' . $this->db->escape( $invoice_no ) . '\', ' . "\n\t\t\t\t\t" . 'store_id = \'' . (int) $order_info['store_id'] . '\', ' . "\n\t\t\t\t\t" . 'store_name = \'' . $this->db->escape( $order_info['store_name'] ) . '\', ' . "\n\t\t\t\t\t" . 'store_url = \'' . $this->db->escape( $order_info['store_url'] ) . '\', ' . "\n\t\t\t\t\t" . 'customer_id = \'' . (int) $order_info['customer_id'] . '\', ' . "\n\t\t\t\t\t" . 'customer_group_id = \'' . (int) $order_info['customer_group_id'] . '\', ' . "\n\t\t\t\t\t" . 'firstname = \'' . $this->db->escape( $order_info['firstname'] ) . '\', ' . "\n\t\t\t\t\t" . 'lastname = \'' . $this->db->escape( $order_info['lastname'] ) . '\', ' . "\n\t\t\t\t\t" . 'email = \'' . $this->db->escape( $order_info['email'] ) . '\', ' . "\n\t\t\t\t\t" . 'telephone = \'' . $this->db->escape( $order_info['telephone'] ) . '\', ' . "\n\t\t\t\t\t" . 'fax = \'' . $this->db->escape( $order_info['fax'] ) . '\', ' . "\n\t\t\t\t\t" . 'custom_field = \'' . $this->db->escape( $custom_field ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_firstname = \'' . $this->db->escape( $order_info['shipping_firstname'] ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_lastname = \'' . $this->db->escape( $order_info['shipping_lastname'] ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_company = \'' . $this->db->escape( $order_info['shipping_company'] ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_address_1 = \'' . $this->db->escape( $order_info['shipping_address_1'] ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_address_2 = \'' . $this->db->escape( $order_info['shipping_address_2'] ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_city = \'' . $this->db->escape( $order_info['shipping_city'] ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_postcode = \'' . $this->db->escape( $order_info['shipping_postcode'] ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_country = \'' . $this->db->escape( $order_info['shipping_country'] ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_country_id = \'' . (int) $order_info['shipping_country_id'] . '\', ' . "\n\t\t\t\t\t" . 'shipping_zone = \'' . $this->db->escape( $order_info['shipping_zone'] ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_zone_id = \'' . (int) $order_info['shipping_zone_id'] . '\', ' . "\n\t\t\t\t\t" . 'shipping_custom_field = \'' . $this->db->escape( $shipping_custom_field ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_method = \'' . $this->db->escape( $order_info['shipping_method'] ) . '\', ' . "\n\t\t\t\t\t" . 'shipping_code = \'' . $this->db->escape( $order_info['shipping_code'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_firstname = \'' . $this->db->escape( $order_info['payment_firstname'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_lastname = \'' . $this->db->escape( $order_info['payment_lastname'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_company = \'' . $this->db->escape( $order_info['payment_company'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_address_1 = \'' . $this->db->escape( $order_info['payment_address_1'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_address_2 = \'' . $this->db->escape( $order_info['payment_address_2'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_city = \'' . $this->db->escape( $order_info['payment_city'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_postcode = \'' . $this->db->escape( $order_info['payment_postcode'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_country = \'' . $this->db->escape( $order_info['payment_country'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_country_id = \'' . (int) $order_info['payment_country_id'] . '\', ' . "\n\t\t\t\t\t" . 'payment_zone = \'' . $this->db->escape( $order_info['payment_zone'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_zone_id = \'' . (int) $order_info['payment_zone_id'] . '\', ' . "\n\t\t\t\t\t" . 'payment_custom_field = \'' . $this->db->escape( $payment_custom_field ) . '\', ' . "\n\t\t\t\t\t" . 'payment_method = \'' . $this->db->escape( $order_info['payment_method'] ) . '\', ' . "\n\t\t\t\t\t" . 'payment_code = \'' . $this->db->escape( $order_info['payment_code'] ) . '\', ' . "\n\t\t\t\t\t" . 'comment = \'' . $this->db->escape( $order_info['comment'] ) . '\', ' . "\n\t\t\t\t\t" . 'order_status_id = \'' . (int) $this->config->get( 'config_order_status_id' ) . '\', ' . "\n\t\t\t\t\t" . 'affiliate_id = \'' . (int) $order_info['affiliate_id'] . '\', ' . "\n\t\t\t\t\t" . 'commission = \'' . (double) $order_info['commission'] . '\', ' . "\n\t\t\t\t\t" . 'language_id = \'' . (int) $order_info['language_id'] . '\', ' . "\n\t\t\t\t\t" . 'currency_id = \'' . (int) $currency_id . '\', ' . "\n\t\t\t\t\t" . 'currency_code = \'' . $this->db->escape( $currency_code ) . '\', ' . "\n\t\t\t\t\t" . 'currency_value = \'' . (double) $currency_value . '\', ' . "\n\t\t\t\t\t" . 'date_added = \'' . $this->db->escape( $date_added ) . '\', ' . "\n\t\t\t\t\t" . 'date_modified = \'' . $this->db->escape( $date_modified ) . '\'';
  57. $this->db->query( $osql );
  58. $new_order_id = $this->db->getLastId( );
  59. }
  60. }
  61.  
  62. return $new_order_id;
  63. }
  64.  
  65. public function addProductsToOrder($order_id, $data)
  66. {
  67. $status = false;
  68.  
  69. if ($this->checkLicense( )) {
  70. $opfields = array( );
  71. $opquery = $this->db->query( 'DESCRIBE ' . DB_PREFIX . 'order_product' );
  72.  
  73. foreach ($opquery->rows as $result) {
  74. $opfields[$result['Field']] = array(
  75. 'field' => $result['Field'],
  76. 'type' => $result['Type']
  77. );
  78. }
  79.  
  80. $oofields = array( );
  81. $ooquery = $this->db->query( 'DESCRIBE ' . DB_PREFIX . 'order_option' );
  82.  
  83. foreach ($ooquery->rows as $result) {
  84. $oofields[$result['Field']] = array(
  85. 'field' => $result['Field'],
  86. 'type' => $result['Type']
  87. );
  88. }
  89.  
  90. $order_info = $this->getOrder( $order_id );
  91.  
  92. if (in_array( $order_info['order_status_id'], array_merge( $this->config->get( 'config_processing_status' ), $this->config->get( 'config_complete_status' ) ) )) {
  93. $restock = true;
  94. }
  95. else {
  96. $restock = false;
  97. }
  98.  
  99. foreach ($data as $old_order_id => $order_data) {
  100. foreach ($order_data as $order_product_id => $order_product) {
  101. $data_product = array( );
  102.  
  103. foreach ($opfields as $key => $value) {
  104. if ((stripos( $value['type'], 'int' ) !== false) || (stripos( $value['type'], 'dec' ) !== false)) {
  105. $data_product['i'][$key] = $order_product['product'][$value['field']];
  106. }
  107. else {
  108. $data_product['s'][$key] = $order_product['product'][$value['field']];
  109. }
  110. }
  111.  
  112. if ($data_product) {
  113. $column_ignore = array(
  114. 'order_id',
  115. 'order_product_id',
  116. 'order_option_id'
  117. );
  118. $opsql = '';
  119.  
  120. foreach ($data_product['i'] as $key => $value) {
  121. if (!(in_array( $key, $column_ignore ))) {
  122. $opsql .= ', `' . $key . '` = \'' . (double) $value . '\'';
  123. }
  124. }
  125.  
  126. foreach ($data_product['s'] as $key => $value) {
  127. if (!(in_array( $key, $column_ignore ))) {
  128. $opsql .= ', `' . $key . '` = \'' . $this->db->escape( $value ) . '\'';
  129. }
  130. }
  131.  
  132. $sql = 'INSERT INTO ' . DB_PREFIX . 'order_product SET order_id = \'' . (int) $order_id . '\'';
  133. $sql .= $opsql;
  134. $this->db->query( $sql );
  135. $new_order_product_id = $this->db->getLastId( );
  136.  
  137. if ($order_product['options']) {
  138. foreach ($order_product['options'] as $options) {
  139. $data_options = array( );
  140.  
  141. foreach ($oofields as $key => $value) {
  142. if ((stripos( $value['type'], 'int' ) !== false) || (stripos( $value['type'], 'dec' ) !== false)) {
  143. $data_options['i'][$key] = $options[$value['field']];
  144. }
  145. else {
  146. $data_options['s'][$key] = $options[$value['field']];
  147. }
  148. }
  149.  
  150. if ($data_options) {
  151. $oosql = '';
  152.  
  153. foreach ($data_options['i'] as $key => $value) {
  154. if (!(in_array( $key, $column_ignore ))) {
  155. $oosql .= ', `' . $key . '` = \'' . (double) $value . '\'';
  156. }
  157. }
  158.  
  159. foreach ($data_options['s'] as $key => $value) {
  160. if (!(in_array( $key, $column_ignore ))) {
  161. $oosql .= ', `' . $key . '` = \'' . $this->db->escape( $value ) . '\'';
  162. }
  163. }
  164.  
  165. $sql = 'INSERT INTO ' . DB_PREFIX . 'order_option SET order_id = \'' . (int) $order_id . '\', order_product_id = \'' . (int) $new_order_product_id . '\'';
  166. $sql .= $oosql;
  167. $this->db->query( $sql );
  168. if ($restock && !(empty( $options['product_option_value_id'] ))) {
  169. $this->db->query( 'UPDATE ' . DB_PREFIX . 'product_option_value SET quantity = (quantity - ' . (double) $order_product['product']['quantity'] . ') WHERE product_option_value_id = \'' . (int) $options['product_option_value_id'] . '\' AND subtract = \'1\'' );
  170. }
  171. }
  172. }
  173. }
  174. if ($restock) {
  175. $this->db->query( 'UPDATE `' . DB_PREFIX . 'product` SET quantity = (quantity - ' . (double) $order_product['product']['quantity'] . ') WHERE product_id = \'' . (int) $order_product['product']['product_id'] . '\' AND subtract = \'1\'' );
  176. }
  177. }
  178. }
  179. }
  180.  
  181. if ($restock) {
  182. $this->cache->delete( 'product' );
  183. }
  184.  
  185. $status = true;
  186. }
  187.  
  188. return $status;
  189. }
  190.  
  191. public function editOrder($data)
  192. {
  193. $order_id = 0;
  194.  
  195. if ($this->checkLicense( )) {
  196. $this->load->language( 'sale/orderpro' );
  197.  
  198. if (!(empty( $data['clone'] ))) {
  199. $data['order_status_id'] = 0;
  200. }
  201.  
  202. $old_products = json_decode( urldecode( $data['old_products'] ), true );
  203.  
  204. if (in_array( $data['order_status_id'], array_merge( $this->config->get( 'config_processing_status' ), $this->config->get( 'config_complete_status' ) ) )) {
  205. if (0 < count( $old_products )) {
  206. foreach ($old_products as $old_product) {
  207. if (!(isset( $old_product['order_option'] ))) {
  208. $old_product['order_option'] = array( );
  209. }
  210.  
  211. $this->addToStock( $old_product['product_id'], $old_product['quantity'], $old_product['order_option'] );
  212. }
  213. }
  214.  
  215. if (isset( $data['order_product'] )) {
  216. foreach ($data['order_product'] as $order_product) {
  217. if (!(isset( $order_product['option'] ))) {
  218. $order_product['option'] = array( );
  219. }
  220.  
  221. $this->substractFromStock( $order_product['product_id'], $order_product['quantity'], $order_product['option'] );
  222. }
  223. }
  224. }
  225.  
  226. $this->load->model( 'setting/store' );
  227. $store_info = $this->model_setting_store->getStore( $data['store_id'] );
  228.  
  229. if ($store_info) {
  230. $store_name = $store_info['name'];
  231. $store_url = $store_info['url'];
  232. }
  233. else {
  234. $store_name = $this->config->get( 'config_name' );
  235. $store_url = HTTP_CATALOG;
  236. }
  237.  
  238. $invoice_prefix = $this->config->get( 'config_invoice_prefix' );
  239. $this->load->model( 'localisation/country' );
  240. $this->load->model( 'localisation/zone' );
  241. $country_info = $this->model_localisation_country->getCountry( $data['shipping_country_id'] );
  242.  
  243. if ($country_info) {
  244. $shipping_country = $country_info['name'];
  245. $shipping_address_format = $country_info['address_format'];
  246. }
  247. else {
  248. $shipping_country = '';
  249. $shipping_address_format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
  250. }
  251.  
  252. $zone_info = $this->model_localisation_zone->getZone( $data['shipping_zone_id'] );
  253.  
  254. if ($zone_info) {
  255. $shipping_zone = $zone_info['name'];
  256. }
  257. else {
  258. $shipping_zone = '';
  259. }
  260.  
  261. $paycountry_info = $this->model_localisation_country->getCountry( $data['payment_country_id'] );
  262.  
  263. if ($paycountry_info) {
  264. $payment_country = $paycountry_info['name'];
  265. $payment_address_format = $paycountry_info['address_format'];
  266. ..................................................................................
  267. .................................................
  268. ....................
RAW Paste Data