Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP5 Decoder for ionCube Encoder)
- *
- * @ Version : 3.0.8.0
- * @ Author : DeZender
- * @ Release on : 25.09.2017
- * @ Official site : http://DeZender.Net
- *
- */
- class ModelSaleOrderpro
- {
- public function getCopyOrder($order_id)
- {
- $new_order_id = 0;
- if ($this->checkLicense( )) {
- $order_info = $this->getOrder( $order_id );
- if ($order_info) {
- $custom_field = '';
- $payment_custom_field = '';
- $shipping_custom_field = '';
- if (isset( $order_info['custom_field'] )) {
- $custom_field = json_encode( $order_info['custom_field'] );
- }
- if (isset( $order_info['payment_custom_field'] )) {
- $payment_custom_field = json_encode( $order_info['payment_custom_field'] );
- }
- if (isset( $order_info['shipping_custom_field'] )) {
- $shipping_custom_field = json_encode( $order_info['shipping_custom_field'] );
- }
- $invoice_no = $this->getInvoiceNo( );
- $this->load->model( 'localisation/currency' );
- if (!(empty( $order_info['currency_code'] ))) {
- $currency_info = $this->model_localisation_currency->getCurrencyByCode( $order_info['currency_code'] );
- }
- else {
- $currency_info = $this->model_localisation_currency->getCurrencyByCode( $this->config->get( 'config_currency' ) );
- }
- $currency_id = ((!(empty( $currency_info['currency_id'] )) ? $currency_info['currency_id'] : 0));
- $currency_code = ((!(empty( $currency_info['code'] )) ? $currency_info['code'] : $this->config->get( 'config_currency' )));
- $currency_value = ((!(empty( $currency_info['value'] )) ? $currency_info['value'] : 1));
- $date_added = date( 'Y-m-d H:i:s', time( ) );
- $date_modified = date( 'Y-m-d H:i:s', time( ) );
- $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'] ) . '\',';
- $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 ) . '\'';
- $this->db->query( $osql );
- $new_order_id = $this->db->getLastId( );
- }
- }
- return $new_order_id;
- }
- public function addProductsToOrder($order_id, $data)
- {
- $status = false;
- if ($this->checkLicense( )) {
- $opfields = array( );
- $opquery = $this->db->query( 'DESCRIBE ' . DB_PREFIX . 'order_product' );
- foreach ($opquery->rows as $result) {
- $opfields[$result['Field']] = array(
- 'field' => $result['Field'],
- 'type' => $result['Type']
- );
- }
- $oofields = array( );
- $ooquery = $this->db->query( 'DESCRIBE ' . DB_PREFIX . 'order_option' );
- foreach ($ooquery->rows as $result) {
- $oofields[$result['Field']] = array(
- 'field' => $result['Field'],
- 'type' => $result['Type']
- );
- }
- $order_info = $this->getOrder( $order_id );
- if (in_array( $order_info['order_status_id'], array_merge( $this->config->get( 'config_processing_status' ), $this->config->get( 'config_complete_status' ) ) )) {
- $restock = true;
- }
- else {
- $restock = false;
- }
- foreach ($data as $old_order_id => $order_data) {
- foreach ($order_data as $order_product_id => $order_product) {
- $data_product = array( );
- foreach ($opfields as $key => $value) {
- if ((stripos( $value['type'], 'int' ) !== false) || (stripos( $value['type'], 'dec' ) !== false)) {
- $data_product['i'][$key] = $order_product['product'][$value['field']];
- }
- else {
- $data_product['s'][$key] = $order_product['product'][$value['field']];
- }
- }
- if ($data_product) {
- $column_ignore = array(
- 'order_id',
- 'order_product_id',
- 'order_option_id'
- );
- $opsql = '';
- foreach ($data_product['i'] as $key => $value) {
- if (!(in_array( $key, $column_ignore ))) {
- $opsql .= ', `' . $key . '` = \'' . (double) $value . '\'';
- }
- }
- foreach ($data_product['s'] as $key => $value) {
- if (!(in_array( $key, $column_ignore ))) {
- $opsql .= ', `' . $key . '` = \'' . $this->db->escape( $value ) . '\'';
- }
- }
- $sql = 'INSERT INTO ' . DB_PREFIX . 'order_product SET order_id = \'' . (int) $order_id . '\'';
- $sql .= $opsql;
- $this->db->query( $sql );
- $new_order_product_id = $this->db->getLastId( );
- if ($order_product['options']) {
- foreach ($order_product['options'] as $options) {
- $data_options = array( );
- foreach ($oofields as $key => $value) {
- if ((stripos( $value['type'], 'int' ) !== false) || (stripos( $value['type'], 'dec' ) !== false)) {
- $data_options['i'][$key] = $options[$value['field']];
- }
- else {
- $data_options['s'][$key] = $options[$value['field']];
- }
- }
- if ($data_options) {
- $oosql = '';
- foreach ($data_options['i'] as $key => $value) {
- if (!(in_array( $key, $column_ignore ))) {
- $oosql .= ', `' . $key . '` = \'' . (double) $value . '\'';
- }
- }
- foreach ($data_options['s'] as $key => $value) {
- if (!(in_array( $key, $column_ignore ))) {
- $oosql .= ', `' . $key . '` = \'' . $this->db->escape( $value ) . '\'';
- }
- }
- $sql = 'INSERT INTO ' . DB_PREFIX . 'order_option SET order_id = \'' . (int) $order_id . '\', order_product_id = \'' . (int) $new_order_product_id . '\'';
- $sql .= $oosql;
- $this->db->query( $sql );
- if ($restock && !(empty( $options['product_option_value_id'] ))) {
- $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\'' );
- }
- }
- }
- }
- if ($restock) {
- $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\'' );
- }
- }
- }
- }
- if ($restock) {
- $this->cache->delete( 'product' );
- }
- $status = true;
- }
- return $status;
- }
- public function editOrder($data)
- {
- $order_id = 0;
- if ($this->checkLicense( )) {
- $this->load->language( 'sale/orderpro' );
- if (!(empty( $data['clone'] ))) {
- $data['order_status_id'] = 0;
- }
- $old_products = json_decode( urldecode( $data['old_products'] ), true );
- if (in_array( $data['order_status_id'], array_merge( $this->config->get( 'config_processing_status' ), $this->config->get( 'config_complete_status' ) ) )) {
- if (0 < count( $old_products )) {
- foreach ($old_products as $old_product) {
- if (!(isset( $old_product['order_option'] ))) {
- $old_product['order_option'] = array( );
- }
- $this->addToStock( $old_product['product_id'], $old_product['quantity'], $old_product['order_option'] );
- }
- }
- if (isset( $data['order_product'] )) {
- foreach ($data['order_product'] as $order_product) {
- if (!(isset( $order_product['option'] ))) {
- $order_product['option'] = array( );
- }
- $this->substractFromStock( $order_product['product_id'], $order_product['quantity'], $order_product['option'] );
- }
- }
- }
- $this->load->model( 'setting/store' );
- $store_info = $this->model_setting_store->getStore( $data['store_id'] );
- if ($store_info) {
- $store_name = $store_info['name'];
- $store_url = $store_info['url'];
- }
- else {
- $store_name = $this->config->get( 'config_name' );
- $store_url = HTTP_CATALOG;
- }
- $invoice_prefix = $this->config->get( 'config_invoice_prefix' );
- $this->load->model( 'localisation/country' );
- $this->load->model( 'localisation/zone' );
- $country_info = $this->model_localisation_country->getCountry( $data['shipping_country_id'] );
- if ($country_info) {
- $shipping_country = $country_info['name'];
- $shipping_address_format = $country_info['address_format'];
- }
- else {
- $shipping_country = '';
- $shipping_address_format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
- }
- $zone_info = $this->model_localisation_zone->getZone( $data['shipping_zone_id'] );
- if ($zone_info) {
- $shipping_zone = $zone_info['name'];
- }
- else {
- $shipping_zone = '';
- }
- $paycountry_info = $this->model_localisation_country->getCountry( $data['payment_country_id'] );
- if ($paycountry_info) {
- $payment_country = $paycountry_info['name'];
- $payment_address_format = $paycountry_info['address_format'];
- ..................................................................................
- .................................................
- ....................
Add Comment
Please, Sign In to add comment