mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-02 19:33:14 +03:00
Fix discount calculation. Attach guest order to crm customer by email
This commit is contained in:
parent
54959b7a15
commit
3be6279f7e
@ -268,14 +268,17 @@ class RetailcrmOrderBuilder
|
|||||||
|
|
||||||
private function buildRegularOrder($dataFromCart = false)
|
private function buildRegularOrder($dataFromCart = false)
|
||||||
{
|
{
|
||||||
$this->createCustomerIfNotExist();
|
$customer = $this->createCustomerIfNotExist();
|
||||||
$order = static::buildCrmOrder(
|
$order = static::buildCrmOrder(
|
||||||
$this->cmsOrder,
|
$this->cmsOrder,
|
||||||
$this->cmsCustomer,
|
$this->cmsCustomer,
|
||||||
$this->cmsCart,
|
$this->cmsCart,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
$dataFromCart
|
$dataFromCart,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
isset($customer['id']) ? $customer['id'] : ''
|
||||||
);
|
);
|
||||||
|
|
||||||
return RetailcrmTools::clearArray($order);
|
return RetailcrmTools::clearArray($order);
|
||||||
@ -797,8 +800,7 @@ class RetailcrmOrderBuilder
|
|||||||
* @param bool $dataFromCart Prefer data from cart
|
* @param bool $dataFromCart Prefer data from cart
|
||||||
* @param string $contactPersonId Contact person id to append
|
* @param string $contactPersonId Contact person id to append
|
||||||
* @param string $contactPersonExternalId Contact person externalId to append.
|
* @param string $contactPersonExternalId Contact person externalId to append.
|
||||||
* @param string $corporateCustomerId Corporate customer id (will be used instead of regular
|
* @param string $customerId Customer id
|
||||||
* customer)
|
|
||||||
* @param string $site Site code (for customer only)
|
* @param string $site Site code (for customer only)
|
||||||
*
|
*
|
||||||
* @return array retailCRM order data
|
* @return array retailCRM order data
|
||||||
@ -813,7 +815,7 @@ class RetailcrmOrderBuilder
|
|||||||
$dataFromCart = false,
|
$dataFromCart = false,
|
||||||
$contactPersonId = '',
|
$contactPersonId = '',
|
||||||
$contactPersonExternalId = '',
|
$contactPersonExternalId = '',
|
||||||
$corporateCustomerId = '',
|
$customerId = '',
|
||||||
$site = ''
|
$site = ''
|
||||||
) {
|
) {
|
||||||
$statusExport = Configuration::get(RetailCRM::STATUS_EXPORT);
|
$statusExport = Configuration::get(RetailCRM::STATUS_EXPORT);
|
||||||
@ -894,18 +896,12 @@ class RetailcrmOrderBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$crmOrder['discountManualAmount'] = round($order->total_discounts, 2);
|
|
||||||
|
|
||||||
if (isset($payment[$paymentType]) && !empty($payment[$paymentType])) {
|
if (isset($payment[$paymentType]) && !empty($payment[$paymentType])) {
|
||||||
$order_payment = array(
|
$order_payment = array(
|
||||||
'externalId' => $order->id . '#' . $order->reference,
|
'externalId' => $order->id . '#' . $order->reference,
|
||||||
'amount' => round($order->total_paid, 2),
|
'amount' => round($order->total_paid, 2),
|
||||||
'type' => $payment[$paymentType]
|
'type' => $payment[$paymentType]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (((float) $crmOrder['discountManualAmount']) > ((float) $order_payment['amount'])) {
|
|
||||||
$crmOrder['discountManualAmount'] = $order_payment['amount'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($order_payment)) {
|
if (isset($order_payment)) {
|
||||||
@ -937,12 +933,23 @@ class RetailcrmOrderBuilder
|
|||||||
$crmOrder['delivery']['code'] = $delivery[$idCarrier];
|
$crmOrder['delivery']['code'] = $delivery[$idCarrier];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset($totalShipping) && $order->total_discounts > $order->total_products_wt ) {
|
||||||
|
$totalShipping -= $order->total_discounts - $order->total_products_wt;
|
||||||
|
$crmOrder['discountManualAmount'] = round($order->total_products_wt, 2);
|
||||||
|
} else {
|
||||||
|
$crmOrder['discountManualAmount'] = round($order->total_discounts, 2);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($totalShipping) && ((int)$totalShipping) > 0) {
|
if (isset($totalShipping) && ((int)$totalShipping) > 0) {
|
||||||
$crmOrder['delivery']['cost'] = round($totalShipping, 2);
|
$crmOrder['delivery']['cost'] = round($totalShipping, 2);
|
||||||
|
} else {
|
||||||
|
$crmOrder['delivery']['cost'] = 0.00;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($totalShippingWithoutTax) && $totalShippingWithoutTax > 0) {
|
if (isset($totalShippingWithoutTax) && $totalShippingWithoutTax > 0) {
|
||||||
$crmOrder['delivery']['netCost'] = round($totalShippingWithoutTax, 2);
|
$crmOrder['delivery']['netCost'] = round($totalShippingWithoutTax, 2);
|
||||||
|
} else {
|
||||||
|
$crmOrder['delivery']['netCost'] = 0.00;
|
||||||
}
|
}
|
||||||
|
|
||||||
$comment = $order->getFirstMessage();
|
$comment = $order->getFirstMessage();
|
||||||
@ -1039,10 +1046,8 @@ class RetailcrmOrderBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($order->id_customer) {
|
if ($order->id_customer) {
|
||||||
if (empty($corporateCustomerId)) {
|
if (!empty($customerId)) {
|
||||||
$crmOrder['customer']['externalId'] = $order->id_customer;
|
$crmOrder['customer']['id'] = $customerId;
|
||||||
} else {
|
|
||||||
$crmOrder['customer']['id'] = $corporateCustomerId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($contactPersonExternalId)) {
|
if (!empty($contactPersonExternalId)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user