Skip to content

Commit

Permalink
Hot fixes for the 1.1.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
zlik committed Jul 28, 2023
1 parent 382ae06 commit c86aa7a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 42 deletions.
4 changes: 2 additions & 2 deletions app/code/Meta/BusinessExtension/Model/System/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,9 +809,9 @@ public function isServerTestModeEnabled(int $scopeId = null, string $scope = nul
*
* @param int|null $scopeId
* @param string|null $scope
* @return string
* @return string|null
*/
public function getServerTestCode(int $scopeId = null, string $scope = null): string
public function getServerTestCode(int $scopeId = null, string $scope = null): ?string
{
return $this->getConfig(
self::XML_PATH_FACEBOOK_CONVERSION_MANAGEMENT_SERVER_TEST_CODE,
Expand Down
81 changes: 47 additions & 34 deletions app/code/Meta/Catalog/Setup/Patch/Data/AddCatalogSwitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class AddCatalogSwitch implements DataPatchInterface
{
private const CORE_CONFIG_TABLE = "core_config_data";
private const CORE_CONFIG_TABLE = 'core_config_data';
/**
* @var ModuleDataSetupInterface
*/
Expand All @@ -21,6 +21,8 @@ class AddCatalogSwitch implements DataPatchInterface
private SystemConfig $systemConfig;

/**
* Class constructor
*
* @param ModuleDataSetupInterface $moduleDataSetup
* @param SystemConfig $systemConfig
*/
Expand All @@ -32,16 +34,27 @@ public function __construct(
$this->systemConfig = $systemConfig;
}

/**
* @inheritdoc
*/
public static function getDependencies()
{
return [];
}

/**
* @inheritdoc
*/
public function getAliases()
{
return [];
}

/**
* Apply patch
*
* @return void
*/
public function apply(): void
{
$connection = $this->moduleDataSetup->getConnection();
Expand All @@ -63,7 +76,7 @@ public function apply(): void
/**
* Updates Store catalog integration
*
* @param $storeId
* @param int $storeId
* @return void
*/
private function updateStoreCatalogIntegration($storeId): void
Expand All @@ -73,79 +86,79 @@ private function updateStoreCatalogIntegration($storeId): void

$isDailyFeedSyncEnabled = $this->fetchValue(
$storeId,
"facebook/catalog_management/daily_product_feed"
'facebook/catalog_management/daily_product_feed'
);
$isCatalogSyncEnabled = $this->fetchValue(
$storeId,
"facebook/catalog_management/enable_catalog_sync"
'facebook/catalog_management/enable_catalog_sync'
);
$outOfStockThresholdOld = $this->fetchValue(
$storeId,
"facebook/inventory_management/out_of_stock_threshold"
'facebook/inventory_management/out_of_stock_threshold'
);
$outOfStockThresholdNew = $this->fetchValue(
$storeId,
"facebook/catalog_management/out_of_stock_threshold"
'facebook/catalog_management/out_of_stock_threshold'
);

if ($isCatalogSyncEnabled == null && $isDailyFeedSyncEnabled != null) {
$connection->insert($coreConfigTable, [
"scope" => $storeId ? "stores" : "default",
"scope_id" => $storeId,
"path" => "facebook/catalog_management/enable_catalog_sync",
"value" => $isDailyFeedSyncEnabled,
'scope' => $storeId ? 'stores' : 'default',
'scope_id' => $storeId,
'path' => 'facebook/catalog_management/enable_catalog_sync',
'value' => $isDailyFeedSyncEnabled,
]);
}

if ($outOfStockThresholdNew == null && $outOfStockThresholdOld != null) {
$connection->insert($coreConfigTable, [
"scope" => $storeId ? "stores" : "default",
"scope_id" => $storeId,
"path" => "facebook/catalog_management/out_of_stock_threshold",
"value" => $outOfStockThresholdOld,
'scope' => $storeId ? 'stores' : 'default',
'scope_id' => $storeId,
'path' => 'facebook/catalog_management/out_of_stock_threshold',
'value' => $outOfStockThresholdOld,
]);
}

$connection->delete($coreConfigTable, [
"scope_id = ?" => $storeId,
"path = ?" => "facebook/catalog_management/daily_product_feed",
'scope_id = ?' => $storeId,
'path = ?' => 'facebook/catalog_management/daily_product_feed',
]);
$connection->delete($coreConfigTable, [
"scope_id = ?" => $storeId,
"path = ?" =>
"facebook/inventory_management/out_of_stock_threshold",
'scope_id = ?' => $storeId,
'path = ?' =>
'facebook/inventory_management/out_of_stock_threshold',
]);
$connection->delete($coreConfigTable, [
"scope_id = ?" => $storeId,
"path = ?" =>
"facebook/catalog_management/incremental_product_updates",
'scope_id = ?' => $storeId,
'path = ?' =>
'facebook/catalog_management/incremental_product_updates',
]);
$connection->delete($coreConfigTable, [
"scope_id = ?" => $storeId,
"path = ?" =>
"facebook/inventory_management/enable_inventory_upload",
'scope_id = ?' => $storeId,
'path = ?' =>
'facebook/inventory_management/enable_inventory_upload',
]);
$connection->delete($coreConfigTable, [
"scope_id = ?" => $storeId,
"path = ?" => "facebook/catalog_management/feed_upload_method",
'scope_id = ?' => $storeId,
'path = ?' => 'facebook/catalog_management/feed_upload_method',
]);
}

/**
* Fetch store config value
*
* @param $storeId
* @param $config_path
* @param int $storeId
* @param string $configPath
* @return mixed|null
*/
private function fetchValue($storeId, $config_path): mixed
private function fetchValue($storeId, $configPath)
{
$connection = $this->moduleDataSetup->getConnection();
$scopeCondition = $connection->prepareSqlCondition("scope_id", [
"eq" => $storeId,
$scopeCondition = $connection->prepareSqlCondition('scope_id', [
'eq' => $storeId,
]);
$pathCondition = $connection->prepareSqlCondition("path", [
"eq" => $config_path,
$pathCondition = $connection->prepareSqlCondition('path', [
'eq' => $configPath,
]);
$query = $connection
->select()
Expand Down
5 changes: 3 additions & 2 deletions app/code/Meta/Sales/Observer/Order/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use GuzzleHttp\Exception\GuzzleException;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Model\Order;
use Meta\BusinessExtension\Helper\GraphAPIAdapter;
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
Expand Down Expand Up @@ -101,8 +102,8 @@ private function cancelOrder(int $storeId, string $fbOrderId)
$this->graphAPIAdapter->cancelOrder($fbOrderId);
} catch (GuzzleException $e) {
$response = $e->getResponse();
$body = json_decode($response->getBody());
throw new Exception(__(
$body = json_decode((string)$response->getBody());
throw new LocalizedException(__(
'Error code: "%1"; Error message: "%2"',
(string)$body->error->code,
(string)($body->error->error_user_msg ?? $body->error->message)
Expand Down
4 changes: 2 additions & 2 deletions app/code/Meta/Sales/Observer/Order/MarkAsShipped.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public function execute(Observer $observer)
$this->shipper->markAsShipped($shipment);
} catch (GuzzleException $e) {
$response = $e->getResponse();
$body = json_decode($response->getBody());
throw new Exception(__(
$body = json_decode((string)$response->getBody());
throw new LocalizedException(__(
'Error code: "%1"; Error message: "%2"',
(string)$body->error->code,
(string)($body->error->error_user_msg ?? $body->error->message)
Expand Down
5 changes: 3 additions & 2 deletions app/code/Meta/Sales/Observer/Order/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use GuzzleHttp\Exception\GuzzleException;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\Data\CreditmemoInterface;
use Magento\Sales\Api\Data\CreditmemoItemInterface as CreditmemoItem;
use Magento\Sales\Api\Data\OrderPaymentInterface;
Expand Down Expand Up @@ -173,8 +174,8 @@ private function refundOrder(
);
} catch (GuzzleException $e) {
$response = $e->getResponse();
$body = json_decode($response->getBody());
throw new Exception(__(
$body = json_decode((string)$response->getBody());
throw new LocalizedException(__(
'Error code: "%1"; Error message: "%2"',
(string)$body->error->code,
(string)($body->error->error_user_msg ?? $body->error->message)
Expand Down

0 comments on commit c86aa7a

Please sign in to comment.