Advertisement
Guest User

Untitled

a guest
Feb 11th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.83 KB | None | 0 0
  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 ('2.1.0.0' <= VERSION) {
  29. if (isset( $order_info['custom_field'] )) {
  30. $custom_field = json_encode( $order_info['custom_field'] );
  31. }
  32.  
  33. if (isset( $order_info['payment_custom_field'] )) {
  34. $payment_custom_field = json_encode( $order_info['payment_custom_field'] );
  35. }
  36.  
  37. if (isset( $order_info['shipping_custom_field'] )) {
  38. $shipping_custom_field = json_encode( $order_info['shipping_custom_field'] );
  39. }
  40. }
  41. else {
  42. if (isset( $order_info['custom_field'] )) {
  43. $custom_field = serialize( $order_info['custom_field'] );
  44. }
  45.  
  46. if (isset( $order_info['payment_custom_field'] )) {
  47. $payment_custom_field = serialize( $order_info['payment_custom_field'] );
  48. }
  49.  
  50. if (isset( $order_info['shipping_custom_field'] )) {
  51. $shipping_custom_field = serialize( $order_info['shipping_custom_field'] );
  52. }
  53. }
  54.  
  55. $invoice_no = $this->getInvoiceNo( );
  56. $this->load->model( 'localisation/currency' );
  57.  
  58. if (!(empty( $order_info['currency_code'] ))) {
  59. $currency_info = $this->model_localisation_currency->getCurrencyByCode( $order_info['currency_code'] );
  60. }
  61. else {
  62. $currency_info = $this->model_localisation_currency->getCurrencyByCode( $this->config->get( 'config_currency' ) );
  63. }
  64.  
  65. $currency_id = ((!(empty( $currency_info['currency_id'] )) ? $currency_info['currency_id'] : 0));
  66. $currency_code = ((!(empty( $currency_info['code'] )) ? $currency_info['code'] : $this->config->get( 'config_currency' )));
  67. $currency_value = ((!(empty( $currency_info['value'] )) ? $currency_info['value'] : 1));
  68. $date_added = date( 'Y-m-d H:i:s', time( ) );
  69. $date_modified = date( 'Y-m-d H:i:s', time( ) );
  70. $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'] ) . '\',';
  71. $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 ) . '\'';
  72. $this->db->query( $osql );
  73. $new_order_id = $this->db->getLastId( );
  74. }
  75. }
  76.  
  77. return $new_order_id;
  78. }
  79.  
  80. public function addProductsToOrder($order_id, $data)
  81. {
  82. $status = false;
  83.  
  84. if ($this->checkLicense( )) {
  85. $opfields = array( );
  86. $opquery = $this->db->query( 'DESCRIBE ' . DB_PREFIX . 'order_product' );
  87.  
  88. foreach ($opquery->rows as $result) {
  89. $opfields[$result['Field']] = array(
  90. 'field' => $result['Field'],
  91. 'type' => $result['Type']
  92. );
  93. }
  94.  
  95. $oofields = array( );
  96. $ooquery = $this->db->query( 'DESCRIBE ' . DB_PREFIX . 'order_option' );
  97.  
  98. foreach ($ooquery->rows as $result) {
  99. $oofields[$result['Field']] = array(
  100. 'field' => $result['Field'],
  101. 'type' => $result['Type']
  102. );
  103. }
  104.  
  105. $order_info = $this->getOrder( $order_id );
  106.  
  107. if (in_array( $order_info['order_status_id'], array_merge( $this->config->get( 'config_processing_status' ), $this->config->get( 'config_complete_status' ) ) )) {
  108. $restock = true;
  109. }
  110. else {
  111. $restock = false;
  112. }
  113.  
  114. foreach ($data as $old_order_id => $order_data) {
  115. foreach ($order_data as $order_product_id => $order_product) {
  116. $data_product = array( );
  117.  
  118. foreach ($opfields as $key => $value) {
  119. if ((stripos( $value['type'], 'int' ) !== false) || (stripos( $value['type'], 'dec' ) !== false)) {
  120. $data_product['i'][$key] = $order_product['product'][$value['field']];
  121. }
  122. else {
  123. $data_product['s'][$key] = $order_product['product'][$value['field']];
  124. }
  125. }
  126.  
  127. if ($data_product) {
  128. $column_ignore = array(
  129. 'order_id',
  130. 'order_product_id',
  131. 'order_option_id'
  132. );
  133. $opsql = '';
  134.  
  135. foreach ($data_product['i'] as $key => $value) {
  136. if (!(in_array( $key, $column_ignore ))) {
  137. $opsql .= ', `' . $key . '` = \'' . (double) $value . '\'';
  138. }
  139. }
  140.  
  141. foreach ($data_product['s'] as $key => $value) {
  142. if (!(in_array( $key, $column_ignore ))) {
  143. $opsql .= ', `' . $key . '` = \'' . $this->db->escape( $value ) . '\'';
  144. }
  145. }
  146.  
  147. $sql = 'INSERT INTO ' . DB_PREFIX . 'order_product SET order_id = \'' . (int) $order_id . '\'';
  148. $sql .= $opsql;
  149. $this->db->query( $sql );
  150. $new_order_product_id = $this->db->getLastId( );
  151.  
  152. if ($order_product['options']) {
  153. foreach ($order_product['options'] as $options) {
  154. $data_options = array( );
  155.  
  156. foreach ($oofields as $key => $value) {
  157. if ((stripos( $value['type'], 'int' ) !== false) || (stripos( $value['type'], 'dec' ) !== false)) {
  158. $data_options['i'][$key] = $options[$value['field']];
  159. }
  160. else {
  161. $data_options['s'][$key] = $options[$value['field']];
  162. }
  163. }
  164.  
  165. if ($data_options) {
  166. $oosql = '';
  167.  
  168. foreach ($data_options['i'] as $key => $value) {
  169. if (!(in_array( $key, $column_ignore ))) {
  170. $oosql .= ', `' . $key . '` = \'' . (double) $value . '\'';
  171. }
  172. }
  173.  
  174. foreach ($data_options['s'] as $key => $value) {
  175. if (!(in_array( $key, $column_ignore ))) {
  176. $oosql .= ', `' . $key . '` = \'' . $this->db->escape( $value ) . '\'';
  177. }
  178. }
  179.  
  180. $sql = 'INSERT INTO ' . DB_PREFIX . 'order_option SET order_id = \'' . (int) $order_id . '\', order_product_id = \'' . (int) $new_order_product_id . '\'';
  181. $sql .= $oosql;
  182. $this->db->query( $sql );
  183. if ($restock && !(empty( $options['product_option_value_id'] ))) {
  184. $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\'' );
  185. }
  186. }
  187. }
  188. }
  189. if ($restock) {
  190. $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\'' );
  191. }
  192. }
  193. }
  194. }
  195.  
  196. if ($restock) {
  197. $this->cache->delete( 'product' );
  198. }
  199.  
  200. $status = true;
  201. }
  202.  
  203. return $status;
  204. }
  205.  
  206. public function editOrder($data)
  207. {
  208. $order_id = 0;
  209.  
  210. if ($this->checkLicense( )) {
  211. $this->load->language( 'sale/orderpro' );
  212. ......................................................................................
  213. ..............................................
  214. .............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement