mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
Merge
This commit is contained in:
commit
d8202ead1d
@ -1650,6 +1650,34 @@ class RetailcrmApiClientV4
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit marketplace configuration
|
||||
*
|
||||
* @param array $configuration
|
||||
*
|
||||
* @throws \RetailCrm\Exception\InvalidJsonException
|
||||
* @throws \RetailCrm\Exception\CurlException
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function marketplaceSettingsEdit(array $configuration)
|
||||
{
|
||||
if (!count($configuration) || empty($configuration['code'])) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Parameter `configuration` must contains a data & configuration `code` must be set'
|
||||
);
|
||||
}
|
||||
|
||||
$code = $configuration['code'];
|
||||
|
||||
return $this->client->makeRequest(
|
||||
"/marketplace/external/setting/$code/edit",
|
||||
RetailcrmHttpClient::METHOD_POST,
|
||||
array('configuration' => json_encode($configuration))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current site
|
||||
*
|
||||
|
@ -178,7 +178,7 @@ class RetailcrmApiClientV5
|
||||
$parameters
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create custom field
|
||||
*
|
||||
@ -211,7 +211,7 @@ class RetailcrmApiClientV5
|
||||
array('customField' => json_encode($customField))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Edit custom field
|
||||
*
|
||||
@ -718,7 +718,7 @@ class RetailcrmApiClientV5
|
||||
'Parameter `id` must be set'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return $this->client->makeRequest(
|
||||
sprintf('/orders/payments/%s/delete', $id),
|
||||
RetailcrmHttpClient::METHOD_POST
|
||||
@ -2292,6 +2292,34 @@ class RetailcrmApiClientV5
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit module configuration
|
||||
*
|
||||
* @param array $configuration
|
||||
*
|
||||
* @throws \RetailCrm\Exception\InvalidJsonException
|
||||
* @throws \RetailCrm\Exception\CurlException
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public function integrationModulesEdit(array $configuration)
|
||||
{
|
||||
if (!count($configuration) || empty($configuration['code'])) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Parameter `configuration` must contains a data & configuration `code` must be set'
|
||||
);
|
||||
}
|
||||
|
||||
$code = $configuration['code'];
|
||||
|
||||
return $this->client->makeRequest(
|
||||
"/integration-modules/$code/edit",
|
||||
RetailcrmHttpClient::METHOD_POST,
|
||||
array('integrationModule' => json_encode($configuration))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current site
|
||||
*
|
||||
|
@ -515,6 +515,7 @@ class RetailcrmHistory
|
||||
}
|
||||
|
||||
$orderCarrier->id_order = $orderToUpdate->id;
|
||||
|
||||
$orderCarrier->update();
|
||||
}
|
||||
}
|
||||
@ -645,44 +646,34 @@ class RetailcrmHistory
|
||||
$product_id = $item['offer']['externalId'];
|
||||
$product_attribute_id = 0;
|
||||
}
|
||||
|
||||
if ($product_id == $orderItem['product_id'] &&
|
||||
$product_attribute_id == $orderItem['product_attribute_id']) {
|
||||
|
||||
$product = new Product((int) $product_id, false, self::$default_lang);
|
||||
$tax = new TaxCore($product->id_tax_rules_group);
|
||||
|
||||
if ($product_attribute_id != 0) {
|
||||
$prodPrice = Combination::getPrice($product_attribute_id);
|
||||
$prodPrice = $prodPrice > 0 ? $prodPrice : $product->price;
|
||||
} else {
|
||||
$prodPrice = $product->price;
|
||||
}
|
||||
|
||||
$prodPrice = $prodPrice + $prodPrice / 100 * $tax->rate;
|
||||
|
||||
// discount
|
||||
if (self::$apiVersion == 5) {
|
||||
$productPrice = $prodPrice - $item['discountTotal'];
|
||||
} else {
|
||||
$productPrice = $prodPrice - $item['discount'];
|
||||
|
||||
if ($item['discountPercent'] > 0) {
|
||||
$productPrice = $productPrice - ($prodPrice / 100 * $item['discountPercent']);
|
||||
}
|
||||
}
|
||||
|
||||
$productPrice = round($productPrice, 2);
|
||||
|
||||
$orderDetail = new OrderDetail($orderItem['id_order_detail']);
|
||||
$orderDetail->unit_price_tax_incl = $productPrice;
|
||||
|
||||
// quantity
|
||||
if (isset($item['quantity']) && $item['quantity'] != $orderItem['product_quantity']) {
|
||||
$orderDetail->product_quantity = $item['quantity'];
|
||||
$orderDetail->product_quantity_in_stock = $item['quantity'];
|
||||
}
|
||||
|
||||
$orderDetail->update();
|
||||
$ItemDiscount = true;
|
||||
unset($order['items'][$key]);
|
||||
@ -699,14 +690,11 @@ class RetailcrmHistory
|
||||
$product_attribute_id = 0;
|
||||
if (strpos($product_id, '#') !== false) {
|
||||
$product_id = explode('#', $product_id);
|
||||
|
||||
$product_attribute_id = $product_id[1];
|
||||
$product_id = $product_id[0];
|
||||
}
|
||||
|
||||
$product = new Product((int) $product_id, false, self::$default_lang);
|
||||
$tax = new TaxCore($product->id_tax_rules_group);
|
||||
|
||||
if ($product_attribute_id != 0) {
|
||||
$productName = htmlspecialchars(
|
||||
strip_tags(Product::getProductName($product_id, $product_attribute_id))
|
||||
@ -717,7 +705,6 @@ class RetailcrmHistory
|
||||
$productName = htmlspecialchars(strip_tags($product->name));
|
||||
$productPrice = $product->price;
|
||||
}
|
||||
|
||||
// discount
|
||||
if ((isset($newItem['discount']) && $newItem['discount'])
|
||||
|| (isset($newItem['discountPercent']) && $newItem['discountPercent'])
|
||||
@ -728,7 +715,6 @@ class RetailcrmHistory
|
||||
$productPrice = $productPrice - ($prodPrice / 100 * $newItem['discountPercent']);
|
||||
$ItemDiscount = true;
|
||||
}
|
||||
|
||||
$orderDetail = new OrderDetail();
|
||||
$orderDetail->id_order = $orderToUpdate->id;
|
||||
$orderDetail->id_order_invoice = $orderToUpdate->invoice_number;
|
||||
@ -746,7 +732,6 @@ class RetailcrmHistory
|
||||
$orderDetail->unit_price_tax_incl = ($productPrice + $productPrice / 100 * $tax->rate);
|
||||
$orderDetail->original_product_price = $productPrice;
|
||||
$orderDetail->save();
|
||||
|
||||
unset($orderDetail);
|
||||
unset($order['items'][$key]);
|
||||
}
|
||||
@ -768,13 +753,11 @@ class RetailcrmHistory
|
||||
$totalPaid = $infoOrder['totalSumm'];
|
||||
$deliveryCost = $infoOrder['delivery']['cost'];
|
||||
$totalDiscount = $deliveryCost + $orderTotalProducts - $totalPaid;
|
||||
|
||||
$orderCartRules = $orderToUpdate->getCartRules();
|
||||
foreach ($orderCartRules as $valCartRules) {
|
||||
$order_cart_rule = new OrderCartRule($valCartRules['id_order_cart_rule']);
|
||||
$order_cart_rule->delete();
|
||||
}
|
||||
|
||||
$orderToUpdate->total_discounts = $totalDiscount;
|
||||
$orderToUpdate->total_discounts_tax_incl = $totalDiscount;
|
||||
$orderToUpdate->total_discounts_tax_excl = $totalDiscount;
|
||||
@ -786,7 +769,6 @@ class RetailcrmHistory
|
||||
$orderToUpdate->total_paid_tax_excl = $totalPaid;
|
||||
$orderToUpdate->total_products_wt = $orderTotalProducts;
|
||||
$orderToUpdate->update();
|
||||
|
||||
unset($ItemDiscount);
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,16 @@ class RetailCRM extends Module
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
$api = new RetailcrmProxy(
|
||||
Configuration::get('RETAILCRM_ADDRESS'),
|
||||
Configuration::get('RETAILCRM_API_TOKEN'),
|
||||
_PS_ROOT_DIR_ . '/retailcrm.log',
|
||||
Configuration::get('RETAILCRM_API_VERSION')
|
||||
);
|
||||
|
||||
$clientId = Configuration::get('RETAILCRM_CLIENT_ID');
|
||||
$this->integrationModule($api, $clientId, Configuration::get('RETAILCRM_API_VERSION'), false);
|
||||
|
||||
return parent::uninstall() &&
|
||||
Configuration::deleteByName('RETAILCRM_ADDRESS') &&
|
||||
Configuration::deleteByName('RETAILCRM_API_TOKEN') &&
|
||||
@ -110,10 +120,12 @@ class RetailCRM extends Module
|
||||
$deliveryDefault = json_encode(Tools::getValue('RETAILCRM_API_DELIVERY_DEFAULT'));
|
||||
$paymentDefault = json_encode(Tools::getValue('RETAILCRM_API_PAYMENT_DEFAULT'));
|
||||
$statusExport = (string)(Tools::getValue('RETAILCRM_STATUS_EXPORT'));
|
||||
$clientId = Configuration::get('RETAILCRM_CLIENT_ID');
|
||||
$settings = array(
|
||||
'address' => $address,
|
||||
'token' => $token,
|
||||
'version' => $version
|
||||
'version' => $version,
|
||||
'clientId' => $clientId
|
||||
);
|
||||
|
||||
$output .= $this->validateForm($settings, $output);
|
||||
@ -738,9 +750,19 @@ class RetailCRM extends Module
|
||||
_PS_ROOT_DIR_ . '/retailcrm.log',
|
||||
$settings['version']
|
||||
);
|
||||
|
||||
$response = $api->deliveryTypesList();
|
||||
|
||||
if ($response !== false) {
|
||||
if (!$settings['clientId']) {
|
||||
$clientId = uniqid();
|
||||
$result = $this->integrationModule($api, $clientId, $settings['version']);
|
||||
|
||||
if ($result) {
|
||||
Configuration::updateValue('RETAILCRM_CLIENT_ID', $clientId);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -759,4 +781,57 @@ class RetailCRM extends Module
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate/deactivate module in marketplace retailCRM
|
||||
*
|
||||
* @param \RetailcrmProxy $apiClient
|
||||
* @param string $clientId
|
||||
* @param string $apiVersion
|
||||
* @param boolean $active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function integrationModule($apiClient, $clientId, $apiVersion, $active = true)
|
||||
{
|
||||
$scheme = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
|
||||
$logo = 'https://s3.eu-central-1.amazonaws.com/retailcrm-billing/images/5b845ce986911-prestashop2.svg';
|
||||
$integrationCode = 'prestashop';
|
||||
$name = 'PrestaShop';
|
||||
$accountUrl = $scheme . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||
|
||||
if ($apiVersion == 'v4') {
|
||||
$configuration = array(
|
||||
'name' => $name,
|
||||
'code' => $integrationCode . '-' . $clientId,
|
||||
'logo' => $logo,
|
||||
'configurationUrl' => $accountUrl,
|
||||
'active' => $active
|
||||
);
|
||||
|
||||
$response = $apiClient->marketplaceSettingsEdit($configuration);
|
||||
} else {
|
||||
$configuration = array(
|
||||
'clientId' => $clientId,
|
||||
'code' => $integrationCode . '-' . $clientId,
|
||||
'integrationCode' => $integrationCode,
|
||||
'active' => $active,
|
||||
'name' => $name,
|
||||
'logo' => $logo,
|
||||
'accountUrl' => $accountUrl
|
||||
);
|
||||
|
||||
$response = $apiClient->integrationModulesEdit($configuration);
|
||||
}
|
||||
|
||||
if (!$response) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user