mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-02 19:33:14 +03:00
Added MultiStore support
This commit is contained in:
parent
07a9056a82
commit
65fb25703b
@ -358,6 +358,7 @@ class RetailcrmCartUploader
|
|||||||
$sql = 'SELECT c.id_cart, c.date_upd
|
$sql = 'SELECT c.id_cart, c.date_upd
|
||||||
FROM ' . _DB_PREFIX_ . 'cart AS c
|
FROM ' . _DB_PREFIX_ . 'cart AS c
|
||||||
WHERE id_customer != 0
|
WHERE id_customer != 0
|
||||||
|
' . Shop::addSqlRestriction(false, 'c') . '
|
||||||
AND TIME_TO_SEC(TIMEDIFF(\'' . pSQL(static::$now->format('Y-m-d H:i:s'))
|
AND TIME_TO_SEC(TIMEDIFF(\'' . pSQL(static::$now->format('Y-m-d H:i:s'))
|
||||||
. '\', date_upd)) >= ' . pSQL(static::$syncDelay) . '
|
. '\', date_upd)) >= ' . pSQL(static::$syncDelay) . '
|
||||||
AND c.id_cart NOT IN(SELECT id_cart from ' . _DB_PREFIX_ . 'orders);';
|
AND c.id_cart NOT IN(SELECT id_cart from ' . _DB_PREFIX_ . 'orders);';
|
||||||
|
@ -98,9 +98,10 @@ class RetailcrmCli
|
|||||||
RetailcrmLogger::output('WARNING: cannot handle signals properly, force stop can cause problems!');
|
RetailcrmLogger::output('WARNING: cannot handle signals properly, force stop can cause problems!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$shortopts = "j:";
|
$shortopts = "j:s:";
|
||||||
$longopts = array(
|
$longopts = array(
|
||||||
"job:",
|
"job:",
|
||||||
|
"shop:",
|
||||||
"set-web-jobs:",
|
"set-web-jobs:",
|
||||||
"query-web-jobs",
|
"query-web-jobs",
|
||||||
"run-jobs",
|
"run-jobs",
|
||||||
@ -110,6 +111,11 @@ class RetailcrmCli
|
|||||||
|
|
||||||
$options = getopt($shortopts, $longopts);
|
$options = getopt($shortopts, $longopts);
|
||||||
$jobName = isset($options['j']) ? $options['j'] : (isset($options['job']) ? $options['job'] : null);
|
$jobName = isset($options['j']) ? $options['j'] : (isset($options['job']) ? $options['job'] : null);
|
||||||
|
$shopId = isset($options['s']) ? $options['s'] : (isset($options['shop']) ? $options['shop'] : null);
|
||||||
|
|
||||||
|
if (Shop::isFeatureActive()) {
|
||||||
|
Shop::setContext(Shop::CONTEXT_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($options['reset-job-manager'])) {
|
if (isset($options['reset-job-manager'])) {
|
||||||
$this->resetJobManager();
|
$this->resetJobManager();
|
||||||
@ -125,7 +131,7 @@ class RetailcrmCli
|
|||||||
$this->help();
|
$this->help();
|
||||||
} else {
|
} else {
|
||||||
$this->setCleanupOnShutdown();
|
$this->setCleanupOnShutdown();
|
||||||
$this->runJob($jobName);
|
$this->runJob($jobName, $shopId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,16 +160,20 @@ class RetailcrmCli
|
|||||||
*
|
*
|
||||||
* @param string $jobName
|
* @param string $jobName
|
||||||
*/
|
*/
|
||||||
private function runJob($jobName)
|
private function runJob($jobName, $shopId)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$result = RetailcrmJobManager::runJob($jobName, true, true);
|
$result = RetailcrmJobManager::runJob($jobName, true, true, $shopId);
|
||||||
RetailcrmLogger::output(sprintf(
|
RetailcrmLogger::output(sprintf(
|
||||||
'Job %s was executed, result: %s',
|
'Job %s was executed, result: %s',
|
||||||
$jobName,
|
$jobName,
|
||||||
$result ? 'true' : 'false'
|
$result ? 'true' : 'false'
|
||||||
));
|
));
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
|
if (Shop::isFeatureActive()) {
|
||||||
|
Shop::setContext(Shop::CONTEXT_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
if ($exception instanceof RetailcrmJobManagerException && $exception->getPrevious() instanceof \Exception) {
|
if ($exception instanceof RetailcrmJobManagerException && $exception->getPrevious() instanceof \Exception) {
|
||||||
$this->printStack($exception->getPrevious());
|
$this->printStack($exception->getPrevious());
|
||||||
} else {
|
} else {
|
||||||
@ -173,6 +183,10 @@ class RetailcrmCli
|
|||||||
self::clearCurrentJob($jobName);
|
self::clearCurrentJob($jobName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Shop::isFeatureActive()) {
|
||||||
|
Shop::setContext(Shop::CONTEXT_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($result) && $result) {
|
if (isset($result) && $result) {
|
||||||
self::clearCurrentJob($jobName);
|
self::clearCurrentJob($jobName);
|
||||||
}
|
}
|
||||||
@ -213,6 +227,15 @@ class RetailcrmCli
|
|||||||
RetailcrmLogger::output(sprintf('> php %s --set-web-jobs true / false - Enable or disable web jobs', $this->cliPath));
|
RetailcrmLogger::output(sprintf('> php %s --set-web-jobs true / false - Enable or disable web jobs', $this->cliPath));
|
||||||
RetailcrmLogger::output(sprintf('> php %s --query-web-jobs - Check web jobs status', $this->cliPath));
|
RetailcrmLogger::output(sprintf('> php %s --query-web-jobs - Check web jobs status', $this->cliPath));
|
||||||
RetailcrmLogger::output();
|
RetailcrmLogger::output();
|
||||||
|
RetailcrmLogger::output(
|
||||||
|
"NOTICE: If you have MultiShop feature enabled, you can additionally " .
|
||||||
|
"specify shop id when manually running job: "
|
||||||
|
);
|
||||||
|
RetailcrmLogger::output("At default jobs are running for all active shops alternately.");
|
||||||
|
RetailcrmLogger::output();
|
||||||
|
RetailcrmLogger::output(sprintf('> php %s -j <job name> -s <shop id> - Runs provided job for specified shop', $this->cliPath));
|
||||||
|
RetailcrmLogger::output(sprintf('> php %s --job <job name> --shop <shop id> - Runs provided job for specified shop', $this->cliPath));
|
||||||
|
RetailcrmLogger::output();
|
||||||
RetailcrmLogger::output(
|
RetailcrmLogger::output(
|
||||||
"WARNING: Commands below are dangerous and should be used only when " .
|
"WARNING: Commands below are dangerous and should be used only when " .
|
||||||
"job manager or cli doesn't work properly."
|
"job manager or cli doesn't work properly."
|
||||||
|
@ -418,6 +418,8 @@ class RetailcrmHistory
|
|||||||
$cart = new Cart();
|
$cart = new Cart();
|
||||||
$cart->id_currency = $default_currency;
|
$cart->id_currency = $default_currency;
|
||||||
$cart->id_lang = self::$default_lang;
|
$cart->id_lang = self::$default_lang;
|
||||||
|
$cart->id_shop = Context::getContext()->shop->id;
|
||||||
|
$cart->id_shop_group = intval(Context::getContext()->shop->id_shop_group);
|
||||||
$cart->id_customer = $customer->id;
|
$cart->id_customer = $customer->id;
|
||||||
$cart->id_address_delivery = (int) $address->id;
|
$cart->id_address_delivery = (int) $address->id;
|
||||||
$cart->id_address_invoice = (int) $address->id;
|
$cart->id_address_invoice = (int) $address->id;
|
||||||
@ -471,9 +473,8 @@ class RetailcrmHistory
|
|||||||
* Create order
|
* Create order
|
||||||
*/
|
*/
|
||||||
$newOrder = new Order();
|
$newOrder = new Order();
|
||||||
$shops = Shop::getShops();
|
|
||||||
$newOrder->id_shop = Context::getContext()->shop->id;
|
$newOrder->id_shop = Context::getContext()->shop->id;
|
||||||
$newOrder->id_shop_group = (int)$shops[Context::getContext()->shop->id]['id_shop_group'];
|
$newOrder->id_shop_group = intval(Context::getContext()->shop->id_shop_group);
|
||||||
$newOrder->reference = $newOrder->generateReference();
|
$newOrder->reference = $newOrder->generateReference();
|
||||||
$newOrder->id_address_delivery = (int) $address->id;
|
$newOrder->id_address_delivery = (int) $address->id;
|
||||||
$newOrder->id_address_invoice = (int) $address->id;
|
$newOrder->id_address_invoice = (int) $address->id;
|
||||||
|
@ -108,6 +108,10 @@ class RetailcrmJobManager
|
|||||||
$current = date_create('now');
|
$current = date_create('now');
|
||||||
$lastRuns = array();
|
$lastRuns = array();
|
||||||
|
|
||||||
|
if (Shop::isFeatureActive()) {
|
||||||
|
Shop::setContext(Shop::CONTEXT_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$lastRuns = static::getLastRuns();
|
$lastRuns = static::getLastRuns();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
@ -172,6 +176,10 @@ class RetailcrmJobManager
|
|||||||
$lastRuns[$job] = new \DateTime('now');
|
$lastRuns[$job] = new \DateTime('now');
|
||||||
}
|
}
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
|
if (Shop::isFeatureActive()) {
|
||||||
|
Shop::setContext(Shop::CONTEXT_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
if ($exception instanceof RetailcrmJobManagerException
|
if ($exception instanceof RetailcrmJobManagerException
|
||||||
&& $exception->getPrevious() instanceof \Exception
|
&& $exception->getPrevious() instanceof \Exception
|
||||||
) {
|
) {
|
||||||
@ -193,6 +201,10 @@ class RetailcrmJobManager
|
|||||||
self::clearCurrentJob($job);
|
self::clearCurrentJob($job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Shop::isFeatureActive()) {
|
||||||
|
Shop::setContext(Shop::CONTEXT_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($result) && $result) {
|
if (isset($result) && $result) {
|
||||||
self::clearCurrentJob($job);
|
self::clearCurrentJob($job);
|
||||||
}
|
}
|
||||||
@ -281,7 +293,7 @@ class RetailcrmJobManager
|
|||||||
* @return bool
|
* @return bool
|
||||||
* @throws \RetailcrmJobManagerException
|
* @throws \RetailcrmJobManagerException
|
||||||
*/
|
*/
|
||||||
public static function runJob($job, $once = false, $cliMode = false)
|
public static function runJob($job, $once = false, $cliMode = false, $shopId = null)
|
||||||
{
|
{
|
||||||
$jobName = self::escapeJobName($job);
|
$jobName = self::escapeJobName($job);
|
||||||
$jobFile = implode(
|
$jobFile = implode(
|
||||||
@ -294,7 +306,7 @@ class RetailcrmJobManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return static::execHere($jobName, $jobFile, $once, $cliMode);
|
return static::execHere($jobName, $jobFile, $once, $cliMode, $shopId);
|
||||||
} catch (\RetailcrmJobManagerException $exception) {
|
} catch (\RetailcrmJobManagerException $exception) {
|
||||||
throw $exception;
|
throw $exception;
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
@ -329,7 +341,7 @@ class RetailcrmJobManager
|
|||||||
*/
|
*/
|
||||||
public static function setCurrentJob($job)
|
public static function setCurrentJob($job)
|
||||||
{
|
{
|
||||||
return (bool) Configuration::updateValue(self::CURRENT_TASK, $job);
|
return (bool)Configuration::updateValue(self::CURRENT_TASK, $job);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -339,7 +351,7 @@ class RetailcrmJobManager
|
|||||||
*/
|
*/
|
||||||
public static function getCurrentJob()
|
public static function getCurrentJob()
|
||||||
{
|
{
|
||||||
return (string) Configuration::get(self::CURRENT_TASK);
|
return (string)Configuration::get(self::CURRENT_TASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -470,7 +482,7 @@ class RetailcrmJobManager
|
|||||||
* @return bool
|
* @return bool
|
||||||
* @throws \RetailcrmJobManagerException
|
* @throws \RetailcrmJobManagerException
|
||||||
*/
|
*/
|
||||||
private static function execHere($jobName, $phpScript, $once = false, $cliMode = false)
|
private static function execHere($jobName, $phpScript, $once = false, $cliMode = false, $shopId = null)
|
||||||
{
|
{
|
||||||
set_time_limit(static::getTimeLimit());
|
set_time_limit(static::getTimeLimit());
|
||||||
|
|
||||||
@ -513,6 +525,7 @@ class RetailcrmJobManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
$job->setCliMode($cliMode);
|
$job->setCliMode($cliMode);
|
||||||
|
$job->setShopId($shopId);
|
||||||
|
|
||||||
self::registerShutdownHandler();
|
self::registerShutdownHandler();
|
||||||
|
|
||||||
|
@ -682,4 +682,15 @@ class RetailcrmTools
|
|||||||
|
|
||||||
return $equal;
|
return $equal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change shop in the context
|
||||||
|
*
|
||||||
|
* @param $id_shop
|
||||||
|
*/
|
||||||
|
public static function setShopContext($id_shop)
|
||||||
|
{
|
||||||
|
Shop::setContext(Shop::CONTEXT_SHOP, $id_shop);
|
||||||
|
Context::getContext()->shop = new Shop($id_shop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,29 +51,39 @@ class RetailcrmAbandonedCartsEvent extends RetailcrmAbstractEvent implements Ret
|
|||||||
|
|
||||||
$this->setRunning();
|
$this->setRunning();
|
||||||
|
|
||||||
$syncCartsActive = Configuration::get(RetailCRM::SYNC_CARTS_ACTIVE);
|
$shops = $this->getShops();
|
||||||
|
|
||||||
if (empty($syncCartsActive)) {
|
|
||||||
RetailcrmLogger::writeCaller(__METHOD__, 'Abandoned carts is disabled, skipping...');
|
|
||||||
|
|
||||||
|
if (!$shops) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$api = RetailcrmTools::getApiClient();
|
foreach ($shops as $shop) {
|
||||||
|
RetailcrmTools::setShopContext(intval($shop['id_shop']));
|
||||||
|
|
||||||
if (empty($api)) {
|
$syncCartsActive = Configuration::get(RetailCRM::SYNC_CARTS_ACTIVE);
|
||||||
RetailcrmLogger::writeCaller(__METHOD__, 'Set API key & URL first');
|
|
||||||
|
|
||||||
return true;
|
if (empty($syncCartsActive)) {
|
||||||
|
RetailcrmLogger::writeCaller(__METHOD__, 'Abandoned carts is disabled, skipping...');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$api = RetailcrmTools::getApiClient();
|
||||||
|
|
||||||
|
if (empty($api)) {
|
||||||
|
RetailcrmLogger::writeCaller(__METHOD__, 'Set API key & URL first');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RetailcrmCartUploader::init();
|
||||||
|
RetailcrmCartUploader::$api = $api;
|
||||||
|
RetailcrmCartUploader::$paymentTypes = array_keys(json_decode(Configuration::get(RetailCRM::PAYMENT), true));
|
||||||
|
RetailcrmCartUploader::$syncStatus = Configuration::get(RetailCRM::SYNC_CARTS_STATUS);
|
||||||
|
RetailcrmCartUploader::setSyncDelay(Configuration::get(RetailCRM::SYNC_CARTS_DELAY));
|
||||||
|
RetailcrmCartUploader::run();
|
||||||
}
|
}
|
||||||
|
|
||||||
RetailcrmCartUploader::init();
|
|
||||||
RetailcrmCartUploader::$api = $api;
|
|
||||||
RetailcrmCartUploader::$paymentTypes = array_keys(json_decode(Configuration::get(RetailCRM::PAYMENT), true));
|
|
||||||
RetailcrmCartUploader::$syncStatus = Configuration::get(RetailCRM::SYNC_CARTS_STATUS);
|
|
||||||
RetailcrmCartUploader::setSyncDelay(Configuration::get(RetailCRM::SYNC_CARTS_DELAY));
|
|
||||||
RetailcrmCartUploader::run();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|||||||
abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
private $cliMode;
|
private $cliMode;
|
||||||
|
private $shopId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
@ -62,7 +63,18 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
|||||||
*/
|
*/
|
||||||
public function setCliMode($mode)
|
public function setCliMode($mode)
|
||||||
{
|
{
|
||||||
$this->cliMode = (bool) $mode;
|
$this->cliMode = (bool)$mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets context shop id.
|
||||||
|
*
|
||||||
|
* @param string|int|null $shopId
|
||||||
|
*/
|
||||||
|
public function setShopId($shopId = null)
|
||||||
|
{
|
||||||
|
if (!is_null($shopId))
|
||||||
|
$this->shopId = intval($shopId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,4 +101,46 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
|||||||
|
|
||||||
return RetailcrmJobManager::setCurrentJob($this->getName());
|
return RetailcrmJobManager::setCurrentJob($this->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns array of active shops or false.
|
||||||
|
*
|
||||||
|
* @return array|false
|
||||||
|
*/
|
||||||
|
protected function getShops()
|
||||||
|
{
|
||||||
|
$shops = Shop::getShops();
|
||||||
|
|
||||||
|
if (Shop::isFeatureActive()) {
|
||||||
|
if ($this->shopId > 0) {
|
||||||
|
if (isset($shops[$this->shopId])) {
|
||||||
|
RetailcrmLogger::writeDebug(
|
||||||
|
__METHOD__,
|
||||||
|
sprintf(
|
||||||
|
"Running job for shop %s (%s).",
|
||||||
|
$shops[$this->shopId]['name'],
|
||||||
|
$this->shopId
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return [$shops[$this->shopId]];
|
||||||
|
} else {
|
||||||
|
RetailcrmLogger::writeDebug(
|
||||||
|
__METHOD__,
|
||||||
|
sprintf(
|
||||||
|
'Shop with id=%s not found.',
|
||||||
|
$this->shopId
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $shops;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return [$shops[Shop::getContextShopID()]];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,11 @@ interface RetailcrmEventInterface
|
|||||||
* @param bool $mode
|
* @param bool $mode
|
||||||
*/
|
*/
|
||||||
public function setCliMode($mode);
|
public function setCliMode($mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets context shop id.
|
||||||
|
*
|
||||||
|
* @param $shopId
|
||||||
|
*/
|
||||||
|
public function setShopId($shopId);
|
||||||
}
|
}
|
||||||
|
@ -51,61 +51,67 @@ class RetailcrmExportEvent extends RetailcrmAbstractEvent implements RetailcrmEv
|
|||||||
|
|
||||||
$this->setRunning();
|
$this->setRunning();
|
||||||
|
|
||||||
$api = RetailcrmTools::getApiClient();
|
$shops = $this->getShops();
|
||||||
|
|
||||||
if (empty($api)) {
|
foreach ($shops as $shop) {
|
||||||
RetailcrmLogger::writeCaller(__METHOD__, 'Set API key & URL first');
|
RetailcrmTools::setShopContext(intval($shop['id_shop']));
|
||||||
|
|
||||||
return true;
|
$api = RetailcrmTools::getApiClient();
|
||||||
}
|
|
||||||
|
|
||||||
$orders = array();
|
if (empty($api)) {
|
||||||
$orderRecords = Order::getOrdersWithInformations();
|
RetailcrmLogger::writeCaller(__METHOD__, 'Set API key & URL first');
|
||||||
$orderBuilder = new RetailcrmOrderBuilder();
|
|
||||||
$orderBuilder->defaultLangFromConfiguration()->setApi($api);
|
|
||||||
|
|
||||||
foreach ($orderRecords as $record) {
|
continue;
|
||||||
$orderBuilder->reset();
|
|
||||||
|
|
||||||
$order = new Order($record['id_order']);
|
|
||||||
|
|
||||||
$orderCart = new Cart($order->id_cart);
|
|
||||||
$orderCustomer = new Customer($order->id_customer);
|
|
||||||
|
|
||||||
$orderBuilder->setCmsOrder($order);
|
|
||||||
|
|
||||||
if (!empty($orderCart->id)) {
|
|
||||||
$orderBuilder->setCmsCart($orderCart);
|
|
||||||
} else {
|
|
||||||
$orderBuilder->setCmsCart(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($orderCustomer->id)) {
|
$orders = array();
|
||||||
$orderBuilder->setCmsCustomer($orderCustomer);
|
$orderRecords = Order::getOrdersWithInformations();
|
||||||
} else {
|
$orderBuilder = new RetailcrmOrderBuilder();
|
||||||
//TODO
|
$orderBuilder->defaultLangFromConfiguration()->setApi($api);
|
||||||
// Caused crash before because of empty RetailcrmOrderBuilder::cmsCustomer.
|
|
||||||
// Current version *shouldn't* do this, but I suggest more tests for guest customers.
|
foreach ($orderRecords as $record) {
|
||||||
$orderBuilder->setCmsCustomer(null);
|
$orderBuilder->reset();
|
||||||
|
|
||||||
|
$order = new Order($record['id_order']);
|
||||||
|
|
||||||
|
$orderCart = new Cart($order->id_cart);
|
||||||
|
$orderCustomer = new Customer($order->id_customer);
|
||||||
|
|
||||||
|
$orderBuilder->setCmsOrder($order);
|
||||||
|
|
||||||
|
if (!empty($orderCart->id)) {
|
||||||
|
$orderBuilder->setCmsCart($orderCart);
|
||||||
|
} else {
|
||||||
|
$orderBuilder->setCmsCart(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($orderCustomer->id)) {
|
||||||
|
$orderBuilder->setCmsCustomer($orderCustomer);
|
||||||
|
} else {
|
||||||
|
//TODO
|
||||||
|
// Caused crash before because of empty RetailcrmOrderBuilder::cmsCustomer.
|
||||||
|
// Current version *shouldn't* do this, but I suggest more tests for guest customers.
|
||||||
|
$orderBuilder->setCmsCustomer(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$orders[] = $orderBuilder->buildOrderWithPreparedCustomer();
|
||||||
|
} catch (\InvalidArgumentException $exception) {
|
||||||
|
RetailcrmLogger::writeCaller('export', $exception->getMessage());
|
||||||
|
RetailcrmLogger::writeNoCaller($exception->getTraceAsString());
|
||||||
|
RetailcrmLogger::output($exception->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
time_nanosleep(0, 500000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
unset($orderRecords);
|
||||||
$orders[] = $orderBuilder->buildOrderWithPreparedCustomer();
|
|
||||||
} catch (\InvalidArgumentException $exception) {
|
$orders = array_chunk($orders, 50);
|
||||||
RetailcrmLogger::writeCaller('export', $exception->getMessage());
|
|
||||||
RetailcrmLogger::writeNoCaller($exception->getTraceAsString());
|
foreach ($orders as $chunk) {
|
||||||
RetailcrmLogger::output($exception->getMessage());
|
$api->ordersUpload($chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
time_nanosleep(0, 500000000);
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($orderRecords);
|
|
||||||
|
|
||||||
$orders = array_chunk($orders, 50);
|
|
||||||
|
|
||||||
foreach ($orders as $chunk) {
|
|
||||||
$api->ordersUpload($chunk);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -51,11 +51,24 @@ class RetailcrmIcmlEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
|||||||
|
|
||||||
$this->setRunning();
|
$this->setRunning();
|
||||||
|
|
||||||
$job = new RetailcrmCatalog();
|
$shops = $this->getShops();
|
||||||
$data = $job->getData();
|
|
||||||
|
|
||||||
$icml = new RetailcrmIcml(Configuration::get('PS_SHOP_NAME'), _PS_ROOT_DIR_ . '/retailcrm.xml');
|
$isMultiStoreActive = Shop::isFeatureActive();
|
||||||
$icml->generate($data[0], $data[1]);
|
|
||||||
|
foreach ($shops as $shop) {
|
||||||
|
RetailcrmTools::setShopContext(intval($shop['id_shop']));
|
||||||
|
|
||||||
|
$job = new RetailcrmCatalog();
|
||||||
|
$data = $job->getData();
|
||||||
|
|
||||||
|
if ($isMultiStoreActive)
|
||||||
|
$icmlFileName = 'retailcrm_' . $shop['id_shop'] . '.xml';
|
||||||
|
else
|
||||||
|
$icmlFileName = 'retailcrm.xml';
|
||||||
|
|
||||||
|
$icml = new RetailcrmIcml($shop['name'], _PS_ROOT_DIR_ . '/' . $icmlFileName);
|
||||||
|
$icml->generate($data[0], $data[1]);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -51,28 +51,34 @@ class RetailcrmInventoriesEvent extends RetailcrmAbstractEvent implements Retail
|
|||||||
|
|
||||||
$this->setRunning();
|
$this->setRunning();
|
||||||
|
|
||||||
if (!Configuration::get(RetailCRM::ENABLE_BALANCES_RECEIVING)) {
|
$shops = $this->getShops();
|
||||||
RetailcrmLogger::writeDebug(
|
|
||||||
'RetailcrmInventoriesEvent',
|
|
||||||
'Balances receiving is not enabled, skipping...'
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
foreach ($shops as $shop) {
|
||||||
|
RetailcrmTools::setShopContext(intval($shop['id_shop']));
|
||||||
|
|
||||||
|
if (!Configuration::get(RetailCRM::ENABLE_BALANCES_RECEIVING)) {
|
||||||
|
RetailcrmLogger::writeDebug(
|
||||||
|
'RetailcrmInventoriesEvent',
|
||||||
|
'Balances receiving is not enabled, skipping...'
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiUrl = Configuration::get(RetailCRM::API_URL);
|
||||||
|
$apiKey = Configuration::get(RetailCRM::API_KEY);
|
||||||
|
|
||||||
|
if (!empty($apiUrl) && !empty($apiKey)) {
|
||||||
|
RetailcrmInventories::$api = new RetailcrmProxy($apiUrl, $apiKey, RetailcrmLogger::getLogFile());
|
||||||
|
} else {
|
||||||
|
RetailcrmLogger::writeCaller('inventories', 'set api key & url first');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RetailcrmInventories::loadStocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
$apiUrl = Configuration::get(RetailCRM::API_URL);
|
|
||||||
$apiKey = Configuration::get(RetailCRM::API_KEY);
|
|
||||||
|
|
||||||
if (!empty($apiUrl) && !empty($apiKey)) {
|
|
||||||
RetailcrmInventories::$api = new RetailcrmProxy($apiUrl, $apiKey, RetailcrmLogger::getLogFile());
|
|
||||||
} else {
|
|
||||||
RetailcrmLogger::writeCaller('inventories', 'set api key & url first');
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
RetailcrmInventories::loadStocks();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
|||||||
|
|
||||||
$this->setRunning();
|
$this->setRunning();
|
||||||
|
|
||||||
$shortopts = 'o:';
|
$shortopts = 'j:o:';
|
||||||
$options = getopt($shortopts);
|
$options = getopt($shortopts);
|
||||||
|
|
||||||
if (!isset($options['o'])) {
|
if (!isset($options['o'])) {
|
||||||
@ -60,6 +60,9 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$orderInstance = new Order($options['o']);
|
||||||
|
RetailcrmTools::setShopContext($orderInstance->id_shop);
|
||||||
|
|
||||||
$apiUrl = Configuration::get(RetailCRM::API_URL);
|
$apiUrl = Configuration::get(RetailCRM::API_URL);
|
||||||
$apiKey = Configuration::get(RetailCRM::API_KEY);
|
$apiKey = Configuration::get(RetailCRM::API_KEY);
|
||||||
|
|
||||||
@ -75,8 +78,6 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
|||||||
$payment = json_decode(Configuration::get(RetailCRM::PAYMENT), true);
|
$payment = json_decode(Configuration::get(RetailCRM::PAYMENT), true);
|
||||||
$status = json_decode(Configuration::get(RetailCRM::STATUS), true);
|
$status = json_decode(Configuration::get(RetailCRM::STATUS), true);
|
||||||
|
|
||||||
$orderInstance = new Order($options['o']);
|
|
||||||
|
|
||||||
$order = array(
|
$order = array(
|
||||||
'externalId' => $orderInstance->id,
|
'externalId' => $orderInstance->id,
|
||||||
'createdAt' => $orderInstance->date_add,
|
'createdAt' => $orderInstance->date_add,
|
||||||
|
@ -51,30 +51,36 @@ class RetailcrmSyncEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
|||||||
|
|
||||||
$this->setRunning();
|
$this->setRunning();
|
||||||
|
|
||||||
if (!Configuration::get(RetailCRM::ENABLE_HISTORY_UPLOADS)) {
|
$shops = $this->getShops();
|
||||||
RetailcrmLogger::writeDebug(
|
|
||||||
__METHOD__,
|
|
||||||
'History uploads is not enabled, skipping...'
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
foreach ($shops as $shop) {
|
||||||
|
RetailcrmTools::setShopContext(intval($shop['id_shop']));
|
||||||
|
|
||||||
|
if (!Configuration::get(RetailCRM::ENABLE_HISTORY_UPLOADS)) {
|
||||||
|
RetailcrmLogger::writeDebug(
|
||||||
|
__METHOD__,
|
||||||
|
'History uploads is not enabled, skipping...'
|
||||||
|
);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiUrl = Configuration::get(RetailCRM::API_URL);
|
||||||
|
$apiKey = Configuration::get(RetailCRM::API_KEY);
|
||||||
|
RetailcrmHistory::$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||||
|
|
||||||
|
if (!empty($apiUrl) && !empty($apiKey)) {
|
||||||
|
RetailcrmHistory::$api = new RetailcrmProxy($apiUrl, $apiKey, RetailcrmLogger::getLogFile());
|
||||||
|
} else {
|
||||||
|
RetailcrmLogger::writeCaller(__METHOD__, 'Set api key & url first');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RetailcrmHistory::customersHistory();
|
||||||
|
RetailcrmHistory::ordersHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
$apiUrl = Configuration::get(RetailCRM::API_URL);
|
|
||||||
$apiKey = Configuration::get(RetailCRM::API_KEY);
|
|
||||||
RetailcrmHistory::$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
|
||||||
|
|
||||||
if (!empty($apiUrl) && !empty($apiKey)) {
|
|
||||||
RetailcrmHistory::$api = new RetailcrmProxy($apiUrl, $apiKey, RetailcrmLogger::getLogFile());
|
|
||||||
} else {
|
|
||||||
RetailcrmLogger::writeCaller(__METHOD__, 'Set api key & url first');
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
RetailcrmHistory::customersHistory();
|
|
||||||
RetailcrmHistory::ordersHistory();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +153,10 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
public function install()
|
public function install()
|
||||||
{
|
{
|
||||||
|
if (Shop::isFeatureActive()) {
|
||||||
|
Shop::setContext(Shop::CONTEXT_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
parent::install() &&
|
parent::install() &&
|
||||||
$this->registerHook('newOrder') &&
|
$this->registerHook('newOrder') &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user