fix edit method, fix api marker, update translations

This commit is contained in:
Alex Lushpai 2014-09-03 13:03:25 +04:00
parent 44258050eb
commit d86ff44e0b
4 changed files with 125 additions and 98 deletions

View File

@ -238,9 +238,9 @@ class ControllerModuleIntarocrm extends Controller {
$this->load->model('sale/customer');
$this->load->model('intarocrm/tools');
$this->load->model('catalog/product');
$this->load->model('localisation/zone');
$my_language = new Language('russian');
$my_language->load('sale/order');
$this->load->language('module/intarocrm');
$settings = $this->model_setting_setting->getSetting('intarocrm');
$settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST);
@ -259,8 +259,17 @@ class ControllerModuleIntarocrm extends Controller {
$totalSettings = $this->model_setting_setting->getSetting('total');
$shippingSettings = $this->model_setting_setting->getSetting('shipping');
foreach ($orders as $order)
{
$delivery = array_flip($settings['intarocrm_delivery']);
$payment = array_flip($settings['intarocrm_payment']);
$status = array_flip($settings['intarocrm_status']);
$ocPayment = $this->model_intarocrm_tools->getOpercartPaymentTypes();
$ocDelivery = $this->model_intarocrm_tools->getOpercartDeliveryMethods();
$zones = $this->model_localisation_zone->getZones();
foreach ($orders as $order) {
if (!isset($order['deleted']) || !$order['deleted']) {
$data = array();
@ -270,6 +279,17 @@ class ControllerModuleIntarocrm extends Controller {
: ''
;
if (isset($order['externalId'])) {
/*
* opercart developers believe that to remove all
* products from the order during the editing is a good
* idea...
*
* so we have to get order data from crm
*
*/
$order = $crm->getOrder($order['externalId']);
} else {
if ($customer_id == '') {
$cData = array(
'customer_group_id' => '1',
@ -320,13 +340,11 @@ class ControllerModuleIntarocrm extends Controller {
$customersIdsFix[] = array('id' => $order['customer']['id'], 'externalId' => (int)$customer_id);
}
}
$delivery = array_flip($settings['intarocrm_delivery']);
$payment = array_flip($settings['intarocrm_payment']);
$status = array_flip($settings['intarocrm_status']);
$ocPayment = $this->model_intarocrm_tools->getOpercartPaymentTypes();
$ocDelivery = $this->model_intarocrm_tools->getOpercartDeliveryMethods();
/*
* Build order data
*/
$data['store_id'] = ($this->config->get('config_store_id') == null)
? 0
@ -363,13 +381,34 @@ class ControllerModuleIntarocrm extends Controller {
;
/*
* TODO: add country & zone id detection
* Country & zone id detection
*/
$data['payment_country_id'] = '176';
$data['shipping_country_id'] = '176';
//$data['payment_zone_id'] = '2778';
//$data['shipping_zone_id'] = '2778';
$country = 0;
$region = '';
if(is_int($order['delivery']['address']['region'])) {
$region = $order['delivery']['address']['region'];
} else {
foreach($zones as $zone) {
if($order['delivery']['address']['region'] == $zone['name']) {
$region = $zone['zone_id'];
}
}
}
$data['payment_country_id'] = isset($order['customer']['address']['country'])
? $order['customer']['address']['country']
: $order['delivery']['address']['country']
;
$data['payment_zone_id'] = isset($order['customer']['address']['region'])
? $order['customer']['address']['region']
: $region
;
$data['shipping_country_id'] = $order['delivery']['address']['country'];
$data['shipping_zone_id'] = $region;
$data['shipping_address'] = '0';
$data['shipping_firstname'] = $order['customer']['firstName'];
@ -391,8 +430,6 @@ class ControllerModuleIntarocrm extends Controller {
$data['payment_method'] = $ocPayment[$data['payment']];
$data['payment_code'] = $payment[$order['paymentType']];
$data['order_status_id'] = $status[$order['status']];
// this data will not retrive from crm for now
$data['tax'] = '';
$data['tax_id'] = '';
@ -433,7 +470,7 @@ class ControllerModuleIntarocrm extends Controller {
array(
'order_total_id' => '',
'code' => 'sub_total',
'title' => $my_language->get('entry_amount'),
'title' => $this->language->get('product_summ'),
'value' => $order['summ'],
'text' => $order['summ'],
'sort_order' => $subtotalSettings['sub_total_sort_order']
@ -449,7 +486,7 @@ class ControllerModuleIntarocrm extends Controller {
array(
'order_total_id' => '',
'code' => 'total',
'title' => $my_language->get('column_total'),
'title' => $this->language->get('column_total'),
'value' => isset($order['totalSumm'])
? $order['totalSumm']
: $order['summ'] + $deliveryCost
@ -462,43 +499,24 @@ class ControllerModuleIntarocrm extends Controller {
)
);
if (isset($order['created'])) {
$data['fromApi'] = true;
}
if (isset($order['externalId'])) {
/*
* opercart developers believe that to remove all
* products from the order during the editing is a good idea...
*
* so we have to get all the goods before orders are breaks
*
*/
$items = $crm->getOrderItems($order['externalId']);
$data['order_product'] = array();
foreach($items as $item) {
$p = $this->model_catalog_product->getProduct($item['offer']['externalId']);
$data['order_product'][] = array(
'product_id' => $item['offer']['externalId'],
'name' => $item['offer']['name'],
'quantity' => $item['quantity'],
'price' => $item['initialPrice'],
'total' => $item['initialPrice'] * $item['quantity'],
'model' => $p['model'],
// this data will not retrive from crm
'order_product_id' => '',
'tax' => 0,
'reward' => 0
);
if(array_key_exists($order['status'], $status)) {
$data['order_status_id'] = $status[$order['status']];
} else {
$tmpOrder = $this->model_sale_order->getOrder($order['externalId']);
$data['order_status_id'] = $tmpOrder['order_status_id'];
}
$this->model_sale_order->editOrder($order['externalId'], $data);
} else {
$data['order_status_id'] = 1;
$this->model_sale_order->addOrder($data);
$last = $this->model_sale_order->getOrders($data = array('order' => 'DESC', 'limit' => 1));
$ordersIdsFix[] = array('id' => $order['id'], 'externalId' => (int) $last[0]['order_id']);
}
}
}

View File

@ -17,6 +17,9 @@ $_['intarocrm_dict_delivery'] = 'Shipment methods';
$_['intarocrm_dict_status'] = 'Order statuses';
$_['intarocrm_dict_payment'] = 'Payment methods';
$_['column_total'] = 'Total';
$_['product_summ'] = 'Amount';
// Errors
$_['error_permission'] = 'Warning! You do not have permission to modify module';
?>

View File

@ -17,6 +17,9 @@ $_['intarocrm_dict_delivery'] = 'Способы доставки';
$_['intarocrm_dict_status'] = 'Статусы';
$_['intarocrm_dict_payment'] = 'Способы оплаты';
$_['column_total'] = 'Итого';
$_['product_summ'] = 'Сумма';
// Errors
$_['error_permission'] = 'У вас недостаточно прав на изменение настроек модуля';
?>

View File

@ -54,6 +54,9 @@ class ApiHelper
$customer['email'] = $data['email'];
$customer['phones'] = array(array('number' => $data['telephone']));
$customer['address']['country'] = $data['payment_country_id'];
$customer['address']['region'] = $data['payment_zone_id'];
$customer['address']['text'] = implode(', ', array(
$data['payment_postcode'],
$data['payment_country'],
@ -96,15 +99,19 @@ class ApiHelper
$order['createdAt'] = date('Y-m-d H:i:s');
$order['paymentType'] = $settings['intarocrm_payment'][$payment_code];
$country = (isset($data['shipping_country'])) ? $data['shipping_country'] : '' ;
$order['delivery'] = array(
'code' => $settings['intarocrm_delivery'][$delivery_code],
'cost' => $deliveryCost,
'address' => array(
'index' => $data['shipping_postcode'],
'city' => $data['shipping_city'],
'country' => $data['shipping_country_id'],
'region' => $data['shipping_zone_id'],
'text' => implode(', ', array(
$data['shipping_postcode'],
$data['shipping_country'],
$country,
$data['shipping_city'],
$data['shipping_address_1'],
$data['shipping_address_2']
@ -112,7 +119,6 @@ class ApiHelper
)
);
$orderProducts = isset($data['products']) ? $data['products'] : $data['order_product'];
foreach ($orderProducts as $product) {
@ -191,13 +197,10 @@ class ApiHelper
}
}
public function getOrderItems($order_id)
public function getOrder($order_id)
{
$order = '';
try {
$order = $this->intaroApi->orderGet($order_id);
return $order['items'];
return $this->intaroApi->orderGet($order_id);
} catch (IntaroCrm\Exception\ApiException $e) {
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . $e->getMessage());
$this->log->addError('['.$this->domain.'] RestApi::orderFixExternalIds:' . json_encode($order));