mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03: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
|
||||
FROM ' . _DB_PREFIX_ . 'cart AS c
|
||||
WHERE id_customer != 0
|
||||
' . Shop::addSqlRestriction(false, 'c') . '
|
||||
AND TIME_TO_SEC(TIMEDIFF(\'' . pSQL(static::$now->format('Y-m-d H:i:s'))
|
||||
. '\', date_upd)) >= ' . pSQL(static::$syncDelay) . '
|
||||
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!');
|
||||
}
|
||||
|
||||
$shortopts = "j:";
|
||||
$longopts = array(
|
||||
$shortopts = "j:s:";
|
||||
$longopts = array(
|
||||
"job:",
|
||||
"shop:",
|
||||
"set-web-jobs:",
|
||||
"query-web-jobs",
|
||||
"run-jobs",
|
||||
@ -110,6 +111,11 @@ class RetailcrmCli
|
||||
|
||||
$options = getopt($shortopts, $longopts);
|
||||
$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'])) {
|
||||
$this->resetJobManager();
|
||||
@ -125,7 +131,7 @@ class RetailcrmCli
|
||||
$this->help();
|
||||
} else {
|
||||
$this->setCleanupOnShutdown();
|
||||
$this->runJob($jobName);
|
||||
$this->runJob($jobName, $shopId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,16 +160,20 @@ class RetailcrmCli
|
||||
*
|
||||
* @param string $jobName
|
||||
*/
|
||||
private function runJob($jobName)
|
||||
private function runJob($jobName, $shopId)
|
||||
{
|
||||
try {
|
||||
$result = RetailcrmJobManager::runJob($jobName, true, true);
|
||||
$result = RetailcrmJobManager::runJob($jobName, true, true, $shopId);
|
||||
RetailcrmLogger::output(sprintf(
|
||||
'Job %s was executed, result: %s',
|
||||
$jobName,
|
||||
$result ? 'true' : 'false'
|
||||
));
|
||||
} catch (\Exception $exception) {
|
||||
if (Shop::isFeatureActive()) {
|
||||
Shop::setContext(Shop::CONTEXT_ALL);
|
||||
}
|
||||
|
||||
if ($exception instanceof RetailcrmJobManagerException && $exception->getPrevious() instanceof \Exception) {
|
||||
$this->printStack($exception->getPrevious());
|
||||
} else {
|
||||
@ -173,6 +183,10 @@ class RetailcrmCli
|
||||
self::clearCurrentJob($jobName);
|
||||
}
|
||||
|
||||
if (Shop::isFeatureActive()) {
|
||||
Shop::setContext(Shop::CONTEXT_ALL);
|
||||
}
|
||||
|
||||
if (isset($result) && $result) {
|
||||
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 --query-web-jobs - Check web jobs status', $this->cliPath));
|
||||
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(
|
||||
"WARNING: Commands below are dangerous and should be used only when " .
|
||||
"job manager or cli doesn't work properly."
|
||||
|
@ -418,6 +418,8 @@ class RetailcrmHistory
|
||||
$cart = new Cart();
|
||||
$cart->id_currency = $default_currency;
|
||||
$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_address_delivery = (int) $address->id;
|
||||
$cart->id_address_invoice = (int) $address->id;
|
||||
@ -471,9 +473,8 @@ class RetailcrmHistory
|
||||
* Create order
|
||||
*/
|
||||
$newOrder = new Order();
|
||||
$shops = Shop::getShops();
|
||||
$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->id_address_delivery = (int) $address->id;
|
||||
$newOrder->id_address_invoice = (int) $address->id;
|
||||
|
@ -108,6 +108,10 @@ class RetailcrmJobManager
|
||||
$current = date_create('now');
|
||||
$lastRuns = array();
|
||||
|
||||
if (Shop::isFeatureActive()) {
|
||||
Shop::setContext(Shop::CONTEXT_ALL);
|
||||
}
|
||||
|
||||
try {
|
||||
$lastRuns = static::getLastRuns();
|
||||
} catch (Exception $exception) {
|
||||
@ -172,6 +176,10 @@ class RetailcrmJobManager
|
||||
$lastRuns[$job] = new \DateTime('now');
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
if (Shop::isFeatureActive()) {
|
||||
Shop::setContext(Shop::CONTEXT_ALL);
|
||||
}
|
||||
|
||||
if ($exception instanceof RetailcrmJobManagerException
|
||||
&& $exception->getPrevious() instanceof \Exception
|
||||
) {
|
||||
@ -193,6 +201,10 @@ class RetailcrmJobManager
|
||||
self::clearCurrentJob($job);
|
||||
}
|
||||
|
||||
if (Shop::isFeatureActive()) {
|
||||
Shop::setContext(Shop::CONTEXT_ALL);
|
||||
}
|
||||
|
||||
if (isset($result) && $result) {
|
||||
self::clearCurrentJob($job);
|
||||
}
|
||||
@ -281,7 +293,7 @@ class RetailcrmJobManager
|
||||
* @return bool
|
||||
* @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);
|
||||
$jobFile = implode(
|
||||
@ -294,7 +306,7 @@ class RetailcrmJobManager
|
||||
}
|
||||
|
||||
try {
|
||||
return static::execHere($jobName, $jobFile, $once, $cliMode);
|
||||
return static::execHere($jobName, $jobFile, $once, $cliMode, $shopId);
|
||||
} catch (\RetailcrmJobManagerException $exception) {
|
||||
throw $exception;
|
||||
} catch (\Exception $exception) {
|
||||
@ -329,7 +341,7 @@ class RetailcrmJobManager
|
||||
*/
|
||||
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()
|
||||
{
|
||||
return (string) Configuration::get(self::CURRENT_TASK);
|
||||
return (string)Configuration::get(self::CURRENT_TASK);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -470,7 +482,7 @@ class RetailcrmJobManager
|
||||
* @return bool
|
||||
* @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());
|
||||
|
||||
@ -513,6 +525,7 @@ class RetailcrmJobManager
|
||||
}
|
||||
|
||||
$job->setCliMode($cliMode);
|
||||
$job->setShopId($shopId);
|
||||
|
||||
self::registerShutdownHandler();
|
||||
|
||||
|
@ -682,4 +682,15 @@ class RetailcrmTools
|
||||
|
||||
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();
|
||||
|
||||
$syncCartsActive = Configuration::get(RetailCRM::SYNC_CARTS_ACTIVE);
|
||||
|
||||
if (empty($syncCartsActive)) {
|
||||
RetailcrmLogger::writeCaller(__METHOD__, 'Abandoned carts is disabled, skipping...');
|
||||
$shops = $this->getShops();
|
||||
|
||||
if (!$shops) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$api = RetailcrmTools::getApiClient();
|
||||
foreach ($shops as $shop) {
|
||||
RetailcrmTools::setShopContext(intval($shop['id_shop']));
|
||||
|
||||
if (empty($api)) {
|
||||
RetailcrmLogger::writeCaller(__METHOD__, 'Set API key & URL first');
|
||||
$syncCartsActive = Configuration::get(RetailCRM::SYNC_CARTS_ACTIVE);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
||||
abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||
{
|
||||
private $cliMode;
|
||||
private $shopId;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
@ -62,7 +63,18 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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();
|
||||
|
||||
$api = RetailcrmTools::getApiClient();
|
||||
$shops = $this->getShops();
|
||||
|
||||
if (empty($api)) {
|
||||
RetailcrmLogger::writeCaller(__METHOD__, 'Set API key & URL first');
|
||||
foreach ($shops as $shop) {
|
||||
RetailcrmTools::setShopContext(intval($shop['id_shop']));
|
||||
|
||||
return true;
|
||||
}
|
||||
$api = RetailcrmTools::getApiClient();
|
||||
|
||||
$orders = array();
|
||||
$orderRecords = Order::getOrdersWithInformations();
|
||||
$orderBuilder = new RetailcrmOrderBuilder();
|
||||
$orderBuilder->defaultLangFromConfiguration()->setApi($api);
|
||||
if (empty($api)) {
|
||||
RetailcrmLogger::writeCaller(__METHOD__, 'Set API key & URL first');
|
||||
|
||||
foreach ($orderRecords as $record) {
|
||||
$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);
|
||||
continue;
|
||||
}
|
||||
|
||||
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);
|
||||
$orders = array();
|
||||
$orderRecords = Order::getOrdersWithInformations();
|
||||
$orderBuilder = new RetailcrmOrderBuilder();
|
||||
$orderBuilder->defaultLangFromConfiguration()->setApi($api);
|
||||
|
||||
foreach ($orderRecords as $record) {
|
||||
$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 {
|
||||
$orders[] = $orderBuilder->buildOrderWithPreparedCustomer();
|
||||
} catch (\InvalidArgumentException $exception) {
|
||||
RetailcrmLogger::writeCaller('export', $exception->getMessage());
|
||||
RetailcrmLogger::writeNoCaller($exception->getTraceAsString());
|
||||
RetailcrmLogger::output($exception->getMessage());
|
||||
unset($orderRecords);
|
||||
|
||||
$orders = array_chunk($orders, 50);
|
||||
|
||||
foreach ($orders as $chunk) {
|
||||
$api->ordersUpload($chunk);
|
||||
}
|
||||
|
||||
time_nanosleep(0, 500000000);
|
||||
}
|
||||
|
||||
unset($orderRecords);
|
||||
|
||||
$orders = array_chunk($orders, 50);
|
||||
|
||||
foreach ($orders as $chunk) {
|
||||
$api->ordersUpload($chunk);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -51,11 +51,24 @@ class RetailcrmIcmlEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
||||
|
||||
$this->setRunning();
|
||||
|
||||
$job = new RetailcrmCatalog();
|
||||
$data = $job->getData();
|
||||
$shops = $this->getShops();
|
||||
|
||||
$icml = new RetailcrmIcml(Configuration::get('PS_SHOP_NAME'), _PS_ROOT_DIR_ . '/retailcrm.xml');
|
||||
$icml->generate($data[0], $data[1]);
|
||||
$isMultiStoreActive = Shop::isFeatureActive();
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -51,28 +51,34 @@ class RetailcrmInventoriesEvent extends RetailcrmAbstractEvent implements Retail
|
||||
|
||||
$this->setRunning();
|
||||
|
||||
if (!Configuration::get(RetailCRM::ENABLE_BALANCES_RECEIVING)) {
|
||||
RetailcrmLogger::writeDebug(
|
||||
'RetailcrmInventoriesEvent',
|
||||
'Balances receiving is not enabled, skipping...'
|
||||
);
|
||||
$shops = $this->getShops();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
||||
|
||||
$this->setRunning();
|
||||
|
||||
$shortopts = 'o:';
|
||||
$shortopts = 'j:o:';
|
||||
$options = getopt($shortopts);
|
||||
|
||||
if (!isset($options['o'])) {
|
||||
@ -60,6 +60,9 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
||||
return true;
|
||||
}
|
||||
|
||||
$orderInstance = new Order($options['o']);
|
||||
RetailcrmTools::setShopContext($orderInstance->id_shop);
|
||||
|
||||
$apiUrl = Configuration::get(RetailCRM::API_URL);
|
||||
$apiKey = Configuration::get(RetailCRM::API_KEY);
|
||||
|
||||
@ -75,8 +78,6 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
||||
$payment = json_decode(Configuration::get(RetailCRM::PAYMENT), true);
|
||||
$status = json_decode(Configuration::get(RetailCRM::STATUS), true);
|
||||
|
||||
$orderInstance = new Order($options['o']);
|
||||
|
||||
$order = array(
|
||||
'externalId' => $orderInstance->id,
|
||||
'createdAt' => $orderInstance->date_add,
|
||||
|
@ -51,30 +51,36 @@ class RetailcrmSyncEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
||||
|
||||
$this->setRunning();
|
||||
|
||||
if (!Configuration::get(RetailCRM::ENABLE_HISTORY_UPLOADS)) {
|
||||
RetailcrmLogger::writeDebug(
|
||||
__METHOD__,
|
||||
'History uploads is not enabled, skipping...'
|
||||
);
|
||||
$shops = $this->getShops();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -153,6 +153,10 @@ class RetailCRM extends Module
|
||||
|
||||
public function install()
|
||||
{
|
||||
if (Shop::isFeatureActive()) {
|
||||
Shop::setContext(Shop::CONTEXT_ALL);
|
||||
}
|
||||
|
||||
return (
|
||||
parent::install() &&
|
||||
$this->registerHook('newOrder') &&
|
||||
|
Loading…
x
Reference in New Issue
Block a user