mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
Offer prices tax
* [fix] offer prices tax & better error logging in job manager
This commit is contained in:
parent
8a3f87ce81
commit
b8d052bda2
@ -221,7 +221,11 @@ class RetailcrmCatalog
|
||||
|
||||
$offerCombination = new Combination($offer['id_product_attribute']);
|
||||
|
||||
$offerPrice = $offerCombination->price + $price;
|
||||
$offerCombinationPrice = !empty($product['rate'])
|
||||
? round($offerCombination->price, 2) + (round($offerCombination->price, 2) * $product['rate'] / 100)
|
||||
: round($offerCombination->price, 2);
|
||||
|
||||
$offerPrice = round($offerCombinationPrice, 2) + $price;
|
||||
$offerPrice = $offerPrice > 0 ? $offerPrice : $price;
|
||||
|
||||
if ($offerCombination->wholesale_price > 0) {
|
||||
|
@ -156,7 +156,12 @@ class RetailcrmCli
|
||||
$result ? 'true' : 'false'
|
||||
));
|
||||
} catch (\Exception $exception) {
|
||||
$this->printStack($exception);
|
||||
if ($exception instanceof RetailcrmJobManagerException && !empty($exception->getPrevious())) {
|
||||
$this->printStack($exception->getPrevious());
|
||||
} else {
|
||||
$this->printStack($exception);
|
||||
}
|
||||
|
||||
self::clearCurrentJob($jobName);
|
||||
} finally {
|
||||
if (isset($result) && $result) {
|
||||
@ -169,10 +174,11 @@ class RetailcrmCli
|
||||
* Prints error details
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @param string $header
|
||||
*/
|
||||
private function printStack($exception)
|
||||
private function printStack($exception, $header = 'Error while executing a job: ')
|
||||
{
|
||||
RetailcrmLogger::output(sprintf('Error while executing a job: %s', $exception->getMessage()));
|
||||
RetailcrmLogger::output(sprintf('%s%s', $header, $exception->getMessage()));
|
||||
RetailcrmLogger::output(sprintf('%s:%d', $exception->getFile(), $exception->getLine()));
|
||||
RetailcrmLogger::output();
|
||||
RetailcrmLogger::output($exception->getTraceAsString());
|
||||
|
@ -172,12 +172,22 @@ class RetailcrmJobManager
|
||||
$lastRuns[$job] = new \DateTime('now');
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
static::handleError(
|
||||
$exception->getFile(),
|
||||
$exception->getMessage(),
|
||||
$exception->getTraceAsString(),
|
||||
$job
|
||||
);
|
||||
if ($exception instanceof RetailcrmJobManagerException && !empty($exception->getPrevious())) {
|
||||
static::handleError(
|
||||
$exception->getPrevious()->getFile(),
|
||||
$exception->getPrevious()->getMessage(),
|
||||
$exception->getPrevious()->getTraceAsString(),
|
||||
$job
|
||||
);
|
||||
} else {
|
||||
static::handleError(
|
||||
$exception->getFile(),
|
||||
$exception->getMessage(),
|
||||
$exception->getTraceAsString(),
|
||||
$job
|
||||
);
|
||||
}
|
||||
|
||||
self::clearCurrentJob($job);
|
||||
} finally {
|
||||
if (isset($result) && $result) {
|
||||
@ -286,7 +296,7 @@ class RetailcrmJobManager
|
||||
} catch (\RetailcrmJobManagerException $exception) {
|
||||
throw $exception;
|
||||
} catch (\Exception $exception) {
|
||||
throw new RetailcrmJobManagerException($exception->getMessage(), $jobFile);
|
||||
throw new RetailcrmJobManagerException($exception->getMessage(), $jobFile, array(), 0, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,7 +454,10 @@ class RetailcrmJobManager
|
||||
|
||||
RetailcrmLogger::writeNoCaller(sprintf('%s: %s (%s)', $file, $msg, implode(', ', $data)));
|
||||
RetailcrmLogger::writeNoCaller($trace);
|
||||
RetailcrmTools::http_response_code(500);
|
||||
|
||||
if (PHP_SAPI != 'cli' && !headers_sent()) {
|
||||
RetailcrmTools::http_response_code(500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,6 +42,51 @@ class RetailcrmCatalogTest extends RetailcrmTestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testIsPricesWithTax()
|
||||
{
|
||||
$products = $this->data[1];
|
||||
$productsPresta = array();
|
||||
$productsPrestaList = Product::getProducts(
|
||||
(int) Configuration::get('PS_LANG_DEFAULT'),
|
||||
0,
|
||||
0,
|
||||
'name',
|
||||
'asc'
|
||||
);
|
||||
|
||||
foreach ($productsPrestaList as $productData) {
|
||||
$productsPresta[$productData['id_product']] = $productData;
|
||||
}
|
||||
|
||||
unset($productsPrestaList);
|
||||
|
||||
foreach ($products as $product) {
|
||||
$this->assertArrayHasKey('productId', $product);
|
||||
$this->assertArrayHasKey('price', $product);
|
||||
|
||||
$prestaProduct = $productsPresta[$product['productId']];
|
||||
$price = !empty($prestaProduct['rate'])
|
||||
? round($prestaProduct['price'], 2) + (round($prestaProduct['price'], 2) * $prestaProduct['rate'] / 100)
|
||||
: round($prestaProduct['price'], 2);
|
||||
|
||||
if (strpos($product['id'], '#') !== false) {
|
||||
$offerId = explode('#', $product['id']);
|
||||
$offerId = $offerId[1];
|
||||
$offerCombination = new Combination($offerId);
|
||||
|
||||
$offerCombinationPrice = !empty($prestaProduct['rate'])
|
||||
? round($offerCombination->price, 2) + (round($offerCombination->price, 2) * $prestaProduct['rate'] / 100)
|
||||
: round($offerCombination->price, 2);
|
||||
$offerPrice = round($offerCombinationPrice, 2) + $price;
|
||||
$offerPrice = $offerPrice > 0 ? $offerPrice : $price;
|
||||
|
||||
$this->assertEquals(round($offerPrice, 2), round($product['price'], 2));
|
||||
} else {
|
||||
$this->assertEquals(round($price, 2), round($product['price'], 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testIcmlGenerate()
|
||||
{
|
||||
$icml = new RetailcrmIcml(Configuration::get('PS_SHOP_NAME'), _PS_ROOT_DIR_ . '/retailcrm.xml');
|
||||
|
Loading…
x
Reference in New Issue
Block a user