diff --git a/Controller/AbandonedCart/LoadCart.php b/Controller/AbandonedCart/LoadCart.php index d953cfb0..69a6f575 100644 --- a/Controller/AbandonedCart/LoadCart.php +++ b/Controller/AbandonedCart/LoadCart.php @@ -151,13 +151,11 @@ public function execute() $customerSessionCustomer = $this->customerSession->getCustomer(); $isLoggedInCustomerDifferent = false; - if ($customerSessionCustomer) { - $customerEmail = $customerSessionCustomer->getEmail(); - $abandonedQuoteCustomerEmail = $abandonedQuote->getCustomer()->getEmail(); - if ($customerEmail !== $abandonedQuoteCustomerEmail) { - $isLoggedInCustomerDifferent = true; - $this->customerSession->logoutCustomer(); - } + $customerEmail = $customerSessionCustomer->getEmail(); + $abandonedQuoteCustomerEmail = $abandonedQuote->getCustomer()->getEmail(); + if ($customerEmail !== $abandonedQuoteCustomerEmail) { + $isLoggedInCustomerDifferent = true; + $this->customerSession->logoutCustomer(); } /** @phpstan-ignore-next-line */ diff --git a/Model/Config.php b/Model/Config.php index 83ec1801..db9e8d00 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -24,26 +24,31 @@ class Config extends CoreConfig /** * Custom attribute code for SMS marketing */ + // phpcs:ignore const YOTPO_CUSTOM_ATTRIBUTE_SMS_MARKETING = 'yotpo_accepts_sms_marketing'; /** * Custom Customer attribute name for synced to yotpo customer */ + // phpcs:ignore const SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME = 'synced_to_yotpo_customer'; /** * Customer entity int table name */ + // phpcs:ignore const CUSTOMER_ENTITY_INT_TABLE_NAME = 'customer_entity_int'; /** * Yotpo customers sync table name */ + // phpcs:ignore const YOTPO_CUSTOMERS_SYNC_TABLE_NAME = 'yotpo_customers_sync'; /** * HTTP Request PATCH method string */ + // phpcs:ignore const PATCH_METHOD_STRING = 'PATCH'; /** diff --git a/Model/Config/Backend/Sync/CustomersScheduler.php b/Model/Config/Backend/Sync/CustomersScheduler.php index e6faa572..16846565 100644 --- a/Model/Config/Backend/Sync/CustomersScheduler.php +++ b/Model/Config/Backend/Sync/CustomersScheduler.php @@ -74,7 +74,9 @@ public function __construct( */ public function afterSave() { - $customersCronExpressionString = $this->getData('groups/sync_settings/groups/customers_sync/fields/frequency/value'); + $customersCronExpressionString = $this->getData( + 'groups/sync_settings/groups/customers_sync/fields/frequency/value' + ); try { $this->configureCronCustomersSync($customersCronExpressionString); diff --git a/Model/Sync/Customers/Cron/CustomersSyncRetry.php b/Model/Sync/Customers/Cron/CustomersSyncRetry.php index 43ea07c7..f563bb5f 100644 --- a/Model/Sync/Customers/Cron/CustomersSyncRetry.php +++ b/Model/Sync/Customers/Cron/CustomersSyncRetry.php @@ -1,6 +1,7 @@ |null $retryCustomersIds * @param int $storeId * @return mixed */ @@ -96,7 +97,7 @@ public function createCustomersCollectionQuery($retryCustomersIds, $storeId) $syncedToYotpoCustomerAttributeName = $this->config::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME; $customersCollectionQuery ->addFieldToFilter('store_id', $storeId) - ->addAttributeToFilter([ + ->addFieldToFilter([ [ 'attribute' => $syncedToYotpoCustomerAttributeName, 'null' => true ], [ 'attribute' => $syncedToYotpoCustomerAttributeName, 'eq' => 0 ] ]) @@ -132,10 +133,10 @@ public function getCustomersIdsForCustomersThatShouldBeRetriedForSync() /** * Prepares Customer sync table data - * @param DataObject $customerSyncToYotpoResponse + * @param mixed $customerSyncToYotpoResponse * @param int $magentoCustomerId - * @param string $storeId - * @return array + * @param int $storeId + * @return array */ public function createCustomerSyncData($customerSyncToYotpoResponse, $magentoCustomerId, $storeId) { @@ -143,7 +144,6 @@ public function createCustomerSyncData($customerSyncToYotpoResponse, $magentoCus $statusCode = $customerSyncToYotpoResponse->getData('status'); $shouldRetry = $this->config->isNetworkRetriableResponse($statusCode); $customerSyncData = [ - /** @phpstan-ignore-next-line */ 'customer_id' => $magentoCustomerId, 'response_code' => $statusCode, 'should_retry' => $shouldRetry, @@ -157,8 +157,8 @@ public function createCustomerSyncData($customerSyncToYotpoResponse, $magentoCus /** * Creates failed customer sync table data * @param int $magentoCustomerId - * @param string $storeId - * @return array + * @param string|int $storeId + * @return array */ public function createServerErrorCustomerSyncData($magentoCustomerId, $storeId) { @@ -166,7 +166,6 @@ public function createServerErrorCustomerSyncData($magentoCustomerId, $storeId) $statusCode = '500'; $shouldRetry = false; $customerSyncData = [ - /** @phpstan-ignore-next-line */ 'customer_id' => $magentoCustomerId, 'response_code' => $statusCode, 'should_retry' => $shouldRetry, @@ -180,7 +179,7 @@ public function createServerErrorCustomerSyncData($magentoCustomerId, $storeId) /** * Inserts or updates custom table data * - * @param array $customerSyncData + * @param array $customerSyncData * @return void */ public function insertOrUpdateCustomerSyncData($customerSyncData) @@ -189,18 +188,18 @@ public function insertOrUpdateCustomerSyncData($customerSyncData) } /** - * @param int $customerId + * @param mixed $customerId * @param string $attributeCode - * @param boolean $isSynced + * @param int $isSynced * @return void * @throws NoSuchEntityException */ - public function insertOrUpdateCustomerAttribute($customerId, $attributeCode, $isSynced = true) + public function insertOrUpdateCustomerAttribute($customerId, $attributeCode, $isSynced = 0) { $customerEntityIntData = [ 'attribute_id' => $attributeCode, 'entity_id' => $customerId, - 'value' => $isSynced + 'value' => (int) $isSynced ]; $this->insertOnDuplicate($this->config::CUSTOMER_ENTITY_INT_TABLE_NAME, [$customerEntityIntData]); diff --git a/Model/Sync/Customers/Processor.php b/Model/Sync/Customers/Processor.php index 7456c729..7be48226 100644 --- a/Model/Sync/Customers/Processor.php +++ b/Model/Sync/Customers/Processor.php @@ -93,13 +93,20 @@ public function __construct( $this->storeManager= $storeManager; $this->yotpoCoreSyncData = $yotpoCoreSyncData; $this->yotpoCustomersSyncRepositoryInterface = $yotpoCustomersSyncRepositoryInterface; - parent::__construct($appEmulation, $resourceConnection, $yotpoSmsConfig, $data, $customerFactory, $yotpoCustomersLogger); + parent::__construct( + $appEmulation, + $resourceConnection, + $yotpoSmsConfig, + $data, + $customerFactory, + $yotpoCustomersLogger + ); } /** * Process customers - * @param array $retryCustomersIds - * @param array $storeIds + * @param array $retryCustomersIds + * @param array $storeIds * @return void * @throws LocalizedException * @throws NoSuchEntityException @@ -168,8 +175,8 @@ public function process($retryCustomersIds = [], $storeIds = []) /** * Process customer entities - * @param array|null $retryCustomersIdsToSync - * @param string|null $storeId + * @param array|null $retryCustomersIdsToSync + * @param int|null $storeId * @param boolean|null $isAttributeSync * @return void * @throws LocalizedException @@ -199,7 +206,8 @@ public function processEntities($retryCustomersIdsToSync = [], $storeId = null, ); $isCustomerAccountShared = $this->config->isCustomerAccountShared(); $storesIdsEligibleForSync = $this->getEligibleStoresForSync(); - $syncedToYotpoCustomerAttributeCode = $this->yotpoCoreSyncData->getAttributeId($this->config::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME); + $syncedToYotpoCustomerAttributeCode = + $this->yotpoCoreSyncData->getAttributeId($this->config::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME); foreach ($customersCollection as $customer) { $customerId = $customer->getId(); try { @@ -219,7 +227,8 @@ public function processEntities($retryCustomersIdsToSync = [], $storeId = null, $this->insertOrUpdateCustomerSyncData($customerSyncData); $this->yotpoCustomersLogger->info( __( - 'Failed to sync customer to Yotpo - Magento Store ID: %1, Magento Store Name: %2, Customer ID: %3 Exception Message: %4', + 'Failed to sync customer to Yotpo - Magento Store ID: %1, + Magento Store Name: %2, Customer ID: %3 Exception Message: %4', $storeId, $this->config->getStoreName($storeId), $customerId, @@ -253,17 +262,15 @@ public function processEntities($retryCustomersIdsToSync = [], $storeId = null, */ public function processCustomer($customer, $customerAddress = null) { - $storeId = $customer->getStoreId(); $storeId = $this->config->getStoreId(); - if ($this->config->syncResetInProgress($storeId, 'customer')) { - $this->yotpoSmsBumpLogger->info( + if ($this->config->isSyncResetInProgress($storeId, 'customer')) { + $this->yotpoCustomersLogger->info( __( 'Customer sync is skipped because sync reset is in progress - Magento Store ID: %1, Name: %2', $storeId, $this->config->getStoreName($storeId) ) ); - return []; } $customerId = $customer->getId(); @@ -302,7 +309,8 @@ public function processCustomer($customer, $customerAddress = null) $this->insertOrUpdateCustomerSyncData($customerSyncData); $this->yotpoCustomersLogger->info( __( - 'Failed to sync Customer to Yotpo - Magento Store ID: %1, Magento Store Name: %2, Customer ID: %3, Exception Message: %4', + 'Failed to sync Customer to Yotpo - Magento Store ID: %1, + Magento Store Name: %2, Customer ID: %3, Exception Message: %4', $storeId, $this->config->getStoreName($storeId), $customerId, @@ -339,9 +347,9 @@ public function retryCustomersSync() /** * @param Customer $customer - * @param string $storeId + * @param int $storeId * @param boolean $isRealTimeSync - * @param null $customerAddress + * @param array|null $customerAddress * @return void * @throws LocalizedException * @throws NoSuchEntityException @@ -349,7 +357,12 @@ public function retryCustomersSync() private function syncCustomer(Customer $customer, $storeId, $isRealTimeSync = false, $customerAddress = null) { $customerId = $customer->getId(); - $customerDataForSync = $this->prepareCustomerDataForSync($customer, $customerId, $isRealTimeSync, $customerAddress); + $customerDataForSync = $this->prepareCustomerDataForSync( + $customer, + $customerId, + $isRealTimeSync, + $customerAddress + ); $response = $this->executeCustomerSyncRequest($customer, $customerDataForSync); if ($response) { $customerSyncData = $this->createCustomerSyncData($response, $customerId, $storeId); @@ -404,15 +417,19 @@ private function executeCustomerSyncRequest($customer, $customerDataForSync = nu /** * @param Customer $customer - * @param array $storesIds + * @param array $storesIds * @param boolean $isRealTimeSync - * @param array $customerAddress + * @param array $customerAddress * @return void * @throws LocalizedException * @throws NoSuchEntityException */ - private function syncSharedStoresCustomer(Customer $customer, $storesIds, $isRealTimeSync = false, $customerAddress = null) - { + private function syncSharedStoresCustomer( + Customer $customer, + $storesIds, + $isRealTimeSync = false, + $customerAddress = null + ) { foreach ($storesIds as $storeId) { $this->emulateFrontendArea($storeId); $this->syncCustomer($customer, $storeId, $isRealTimeSync, $customerAddress); @@ -427,8 +444,12 @@ private function syncSharedStoresCustomer(Customer $customer, $storesIds, $isRea * @param mixed|null $customerAddress * @return mixed */ - private function prepareCustomerDataForSync(Customer $customer, $customerId, $isRealTimeSync, $customerAddress = null) - { + private function prepareCustomerDataForSync( + Customer $customer, + $customerId, + $isRealTimeSync, + $customerAddress = null + ) { if (isset($this->customerDataPrepared[$customerId])) { $customerDataForSync = $this->customerDataPrepared[$customerId]; } else { @@ -440,14 +461,14 @@ private function prepareCustomerDataForSync(Customer $customer, $customerId, $is } /** - * @return array + * @return array * @throws LocalizedException * @throws NoSuchEntityException */ private function getEligibleStoresForSync(): array { $storesIdsEligibleForSync = []; - $storesIds = $this->config->getAllStoreIds(false); + $storesIds = (array) $this->config->getAllStoreIds(false); foreach ($storesIds as $storeId) { if ($this->config->isCustomerSyncActive($storeId)) { $storesIdsEligibleForSync[] = $storeId; @@ -470,11 +491,14 @@ private function updateLastSyncDate($currentTime) } /** - * @param string $customerId + * @param mixed $customerId + * @return void */ private function updateSyncedToYotpoCustomerAttributeAsSynced($customerId) { - $syncedToYotpoCustomerAttributeCode = $this->yotpoCoreSyncData->getAttributeId($this->config::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME); + $syncedToYotpoCustomerAttributeCode = $this->yotpoCoreSyncData->getAttributeId( + $this->config::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME + ); $this->insertOrUpdateCustomerAttribute($customerId, $syncedToYotpoCustomerAttributeCode); } } diff --git a/Model/Sync/Customers/Services/CustomersAttributesService.php b/Model/Sync/Customers/Services/CustomersAttributesService.php index 4b9ca75f..d736c8ae 100644 --- a/Model/Sync/Customers/Services/CustomersAttributesService.php +++ b/Model/Sync/Customers/Services/CustomersAttributesService.php @@ -16,9 +16,6 @@ */ class CustomersAttributesService extends AbstractJobs { - /** - * Maximum reset customers sync retries attempts - */ const MAXIMUM_RESET_CUSTOMERS_SYNC_RETRIES_ATTEMPTS = 3; /** @@ -43,6 +40,7 @@ class CustomersAttributesService extends AbstractJobs /** * Saves the reset customers sync attempts for retrying rest + * @var int */ protected $currentResetCustomersSyncAttempts; @@ -71,12 +69,14 @@ public function __construct( /** * @param Customer $customer - * @param boolean $attributeValue + * @param int $attributeValue * @return void */ public function updateSyncedToYotpoCustomerAttribute($customer, $attributeValue) { - $syncedToYotpoCustomerAttributeCode = $this->yotpoCoreSyncData->getAttributeId($this->config::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME); + $syncedToYotpoCustomerAttributeCode = $this->yotpoCoreSyncData->getAttributeId( + $this->config::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME + ); $this->customersMain->insertOrUpdateCustomerAttribute( $customer->getId(), $syncedToYotpoCustomerAttributeCode, @@ -91,7 +91,9 @@ public function resetCustomersSyncedToYotpoAttribute() { try { $connection = $this->resourceConnection->getConnection(); - $syncedToYotpoCustomerAttributeCode = $this->yotpoCoreSyncData->getAttributeId($this->config::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME); + $syncedToYotpoCustomerAttributeCode = $this->yotpoCoreSyncData->getAttributeId( + $this->config::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME + ); $customerEntityIntTableName = $this->config::CUSTOMER_ENTITY_INT_TABLE_NAME; $sqlUpdateLimit = $this->config->getUpdateSqlLimit(); $customersThatWereProcesssedQuery = $connection->select()->from( @@ -107,7 +109,7 @@ public function resetCustomersSyncedToYotpoAttribute() $sqlUpdateLimit ); - while(count($rowsToUpdate = $connection->fetchAssoc($customersThatWereProcesssedQuery, 'value_id'))) { + while (count($rowsToUpdate = $connection->fetchAssoc($customersThatWereProcesssedQuery, 'value_id'))) { $connection->update( $customerEntityIntTableName, [ 'value' => 0 ], diff --git a/Model/Sync/Customers/Services/CustomersService.php b/Model/Sync/Customers/Services/CustomersService.php index e0984a52..a2b471ff 100644 --- a/Model/Sync/Customers/Services/CustomersService.php +++ b/Model/Sync/Customers/Services/CustomersService.php @@ -59,8 +59,7 @@ public function __construct( /** * Retry processing failed customers * @return void - * @throws LocalizedException - * @throws NoSuchEntityException + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function processCustomersSyncTableResync() { @@ -88,7 +87,8 @@ public function processCustomersSyncTableResync() $this->config->getStoreName($storeId) ) ); - $customersIdsForSync = $this->customersProcessorMain->getCustomersIdsForCustomersThatShouldBeRetriedForSync(); + $customersIdsForSync = + $this->customersProcessorMain->getCustomersIdsForCustomersThatShouldBeRetriedForSync(); $this->processFailedCustomerEntities($customersIdsForSync); $this->yotpoCustomersLogger->info( @@ -98,10 +98,11 @@ public function processCustomersSyncTableResync() $this->config->getStoreName($storeId) ) ); - } catch (Exception $exception) { + } catch (\Exception $exception) { $this->yotpoCustomersLogger->info( __( - 'Failed to process Customers retry sync for - Magento Store ID: %1, Magento Store Name: %2, Reason: %3', + 'Failed to process Customers retry sync for - Magento Store ID: %1, + Magento Store Name: %2, Reason: %3', $storeId, $this->config->getStoreName($storeId), $exception->getMessage() @@ -114,11 +115,10 @@ public function processCustomersSyncTableResync() } /** - * Process customer entities - * @param array $customersIdsForResync + * @param array $customersIdsForResync * @return void - * @throws LocalizedException - * @throws NoSuchEntityException + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \Magento\Framework\Exception\NoSuchEntityException */ private function processFailedCustomerEntities($customersIdsForResync) { diff --git a/Observer/Config/CronFrequency.php b/Observer/Config/CronFrequency.php index bbfdb4ea..00c99a16 100644 --- a/Observer/Config/CronFrequency.php +++ b/Observer/Config/CronFrequency.php @@ -29,7 +29,10 @@ class CronFrequency extends YotpoCoreCronFrequency * @var array */ protected $cronFrequency = [ - 'customers_sync_frequency' => ['config_path' => '','job_code' => 'yotpo_cron_messaging_customers_sync,yotpo_cron_messaging_customers_sync_retry'] + 'customers_sync_frequency' => [ + 'config_path' => '', + 'job_code' => 'yotpo_cron_messaging_customers_sync,yotpo_cron_messaging_customers_sync_retry' + ] ]; /** diff --git a/Observer/Config/Customer/CustomerConfigSave.php b/Observer/Config/Customer/CustomerConfigSave.php index 3487bc58..83c6c369 100644 --- a/Observer/Config/Customer/CustomerConfigSave.php +++ b/Observer/Config/Customer/CustomerConfigSave.php @@ -18,16 +18,19 @@ class CustomerConfigSave implements ObserverInterface const CUSTOMER_ACCOUNT_SHARE_CONFIG_PATH = 'customer/account_share/scope'; /** - * @param Config $config + * @var Config */ protected $config; /** - * @param Config $config - * @param CustomersAttributesService $customersAttributesService + * @var CustomersAttributesService */ protected $customersAttributesService; + /** + * @param Config $config + * @param CustomersAttributesService $customersAttributesService + */ public function __construct( Config $config, CustomersAttributesService $customersAttributesService @@ -42,7 +45,8 @@ public function __construct( */ public function execute(Observer $observer) { - $isCustomerAccountShareSettingChangedToEnabled = $this->checkCustomerAccountShareSettingChangedToEnabled($observer); + $isCustomerAccountShareSettingChangedToEnabled = + $this->checkCustomerAccountShareSettingChangedToEnabled($observer); if (!$isCustomerAccountShareSettingChangedToEnabled) { return; } diff --git a/Observer/CustomerSaveAfter.php b/Observer/CustomerSaveAfter.php index 736048e5..74bba595 100644 --- a/Observer/CustomerSaveAfter.php +++ b/Observer/CustomerSaveAfter.php @@ -88,7 +88,7 @@ public function execute(Observer $observer) $customer = $observer->getEvent()->getCustomer(); $isCustomerSyncActive = $this->yotpoSmsConfig->isCustomerSyncActive(); if (!$this->request->getParam('custSync')) { - $this->customersAttributesService->updateSyncedToYotpoCustomerAttribute($customer, false); + $this->customersAttributesService->updateSyncedToYotpoCustomerAttribute($customer, 0); $isCheckoutInProgress = $this->request->getParam('_checkout_in_progress', null); if ($isCustomerSyncActive && $isCheckoutInProgress === null) { diff --git a/Plugin/Checkout/DefaultConfigProviderPlugin.php b/Plugin/Checkout/DefaultConfigProviderPlugin.php index 57832555..38f1e28b 100644 --- a/Plugin/Checkout/DefaultConfigProviderPlugin.php +++ b/Plugin/Checkout/DefaultConfigProviderPlugin.php @@ -47,7 +47,6 @@ class DefaultConfigProviderPlugin protected $checkoutProcessor; /** - * @method __construct * @param CheckoutSession $checkoutSession * @param ResourceConnection $resourceConnection * @param YotpoSmsbumpSession $yotpoSmsBumpSession @@ -82,7 +81,7 @@ public function afterGetConfig($subject, $result) $quote = $this->checkoutSession->getQuote(); $billingAddress = $quote->getBillingAddress(); $shippingAddress = $quote->getShippingAddress(); - $email = $shippingAddress ? $shippingAddress->getEmail() : null; + $email = $shippingAddress->getEmail(); if (!$email) { $items = $this->getAbandonedCartData($quote); @@ -102,7 +101,7 @@ public function afterGetConfig($subject, $result) $result['validatedEmailValue'] = $email; } - if ($billingAddress && $billingAddress->getCountryId()) { + if ($billingAddress->getCountryId()) { $this->checkoutProcessor->process($quote); } diff --git a/Plugin/Quote/Model/AbstractCheckoutTrigger.php b/Plugin/Quote/Model/AbstractCheckoutTrigger.php index a707f2ce..c570f21d 100644 --- a/Plugin/Quote/Model/AbstractCheckoutTrigger.php +++ b/Plugin/Quote/Model/AbstractCheckoutTrigger.php @@ -7,7 +7,6 @@ use Magento\Quote\Api\CartRepositoryInterface; use Yotpo\SmsBump\Model\Config; use Magento\Quote\Model\Quote as QuoteModel; -use Magento\Quote\Api\Data\AddressInterface; /** * Class AbstractCheckoutTrigger @@ -36,7 +35,6 @@ class AbstractCheckoutTrigger protected $yotpoMessagingConfig; /** - * @method __construct * @param CheckoutProcessor $checkoutProcessor * @param Registry $registry * @param CartRepositoryInterface $quoteRepository @@ -55,8 +53,8 @@ public function __construct( } /** - * @method checkoutSync * @param QuoteModel $quote + * @return void */ protected function checkoutSync(QuoteModel $quote) { diff --git a/Plugin/Quote/Model/BillingAddressManagement.php b/Plugin/Quote/Model/BillingAddressManagement.php index 864ed6be..a91ea3b0 100644 --- a/Plugin/Quote/Model/BillingAddressManagement.php +++ b/Plugin/Quote/Model/BillingAddressManagement.php @@ -12,7 +12,6 @@ class BillingAddressManagement extends AbstractCheckoutTrigger { /** - * @method afterAssign * @param QuoteBillingAddressManagement $billingAddressManagement * @param int $result * @param int $cartId @@ -20,11 +19,17 @@ class BillingAddressManagement extends AbstractCheckoutTrigger * @param boolean $useForShipping * @return int */ - public function afterAssign(QuoteBillingAddressManagement $billingAddressManagement, $result, $cartId, AddressInterface $address, $useForShipping = false) - { + public function afterAssign( + QuoteBillingAddressManagement $billingAddressManagement, + $result, + $cartId, + AddressInterface $address, + $useForShipping = false + ) { if ($this->registry->registry('yotpo_smsbump_quote_set_billing_address_plugin')) { $this->registry->unregister('yotpo_smsbump_quote_set_billing_address_plugin'); } elseif ($this->yotpoMessagingConfig->isCheckoutSyncActive()) { + /** @var \Magento\Quote\Model\Quote $quote **/ $quote = $this->quoteRepository->getActive($cartId); $this->checkoutSync($quote); } diff --git a/Plugin/Quote/Model/Quote.php b/Plugin/Quote/Model/Quote.php index 293703b2..a07317b5 100644 --- a/Plugin/Quote/Model/Quote.php +++ b/Plugin/Quote/Model/Quote.php @@ -12,7 +12,6 @@ class Quote extends AbstractCheckoutTrigger { /** - * @method afterSetBillingAddress * @param QuoteModel $quote * @param QuoteModel $result * @param AddressInterface $address @@ -21,7 +20,7 @@ class Quote extends AbstractCheckoutTrigger public function afterSetBillingAddress(QuoteModel $quote, $result, AddressInterface $address = null) { $this->checkoutSync($quote); - if (!$this->registry->registry('yotpo_smsbump_quote_set_billing_address_plugin')){ + if (!$this->registry->registry('yotpo_smsbump_quote_set_billing_address_plugin')) { $this->registry->register('yotpo_smsbump_quote_set_billing_address_plugin', 1); } @@ -29,7 +28,6 @@ public function afterSetBillingAddress(QuoteModel $quote, $result, AddressInterf } /** - * @method afterSetShippingAddress * @param QuoteModel $quote * @param QuoteModel $result * @param AddressInterface $address @@ -38,7 +36,7 @@ public function afterSetBillingAddress(QuoteModel $quote, $result, AddressInterf public function afterSetShippingAddress(QuoteModel $quote, $result, AddressInterface $address = null) { $this->checkoutSync($quote); - if (!$this->registry->registry('yotpo_smsbump_quote_set_shipping_address_plugin')){ + if (!$this->registry->registry('yotpo_smsbump_quote_set_shipping_address_plugin')) { $this->registry->register('yotpo_smsbump_quote_set_shipping_address_plugin', 1); } @@ -46,7 +44,6 @@ public function afterSetShippingAddress(QuoteModel $quote, $result, AddressInter } /** - * @method afterSave * @param QuoteModel $quote * @param QuoteModel $result * @return QuoteModel diff --git a/Plugin/Quote/Model/ShippingAddressManagement.php b/Plugin/Quote/Model/ShippingAddressManagement.php index 07a89ce9..bfc70da4 100644 --- a/Plugin/Quote/Model/ShippingAddressManagement.php +++ b/Plugin/Quote/Model/ShippingAddressManagement.php @@ -2,6 +2,8 @@ namespace Yotpo\SmsBump\Plugin\Quote\Model; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Quote\Model\ShippingAddressManagement as QuoteShippingAddressManagement; use Magento\Quote\Api\Data\AddressInterface; @@ -12,18 +14,24 @@ class ShippingAddressManagement extends AbstractCheckoutTrigger { /** - * @method afterAssign * @param QuoteShippingAddressManagement $shippingAddressManagement * @param int $result * @param int $cartId * @param AddressInterface $address - * @return int + * @return mixed + * @throws LocalizedException + * @throws NoSuchEntityException */ - public function afterAssign(QuoteShippingAddressManagement $shippingAddressManagement, $result, $cartId, AddressInterface $address) - { + public function afterAssign( + QuoteShippingAddressManagement $shippingAddressManagement, + $result, + $cartId, + AddressInterface $address + ) { if ($this->registry->registry('yotpo_smsbump_quote_set_shipping_address_plugin')) { $this->registry->unregister('yotpo_smsbump_quote_set_shipping_address_plugin'); } elseif ($this->yotpoMessagingConfig->isCheckoutSyncActive()) { + /** @var \Magento\Quote\Model\Quote $quote **/ $quote = $this->quoteRepository->getActive($cartId); $this->checkoutSync($quote); } diff --git a/Setup/Patch/Data/CustomCustomerAttributeSyncedToYotpo.php b/Setup/Patch/Data/CustomCustomerAttributeSyncedToYotpo.php index 3168ae94..da666d1e 100644 --- a/Setup/Patch/Data/CustomCustomerAttributeSyncedToYotpo.php +++ b/Setup/Patch/Data/CustomCustomerAttributeSyncedToYotpo.php @@ -10,7 +10,8 @@ use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface; use Yotpo\SmsBump\Model\Config as MessagingConfig; -class CustomCustomerAttributeSyncedToYotpo extends CoreCustomCustomerAttributeSyncedToYotpo implements DataPatchInterface +class CustomCustomerAttributeSyncedToYotpo extends CoreCustomCustomerAttributeSyncedToYotpo implements + DataPatchInterface { const CUSTOMER_SETUP_FACTORY_SETUP_KEY = 'setup'; @@ -49,14 +50,20 @@ public function __construct( */ public function apply() { - $customerSetup = $this->customerSetupFactory->create([ $this::CUSTOMER_SETUP_FACTORY_SETUP_KEY => $this->moduleDataSetup ]); - $customerSetup->addAttribute(Customer::ENTITY, $this->messagingConfig::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME, [ - 'type' => 'int', - 'label' => 'Synced to Yotpo Customer', - 'required' => false, - 'visible' => false, - 'user_defined' => false - ]); + $customerSetup = + $this->customerSetupFactory->create([$this::CUSTOMER_SETUP_FACTORY_SETUP_KEY => $this->moduleDataSetup ]); + $customerSetup->addAttribute( + Customer::ENTITY, + $this->messagingConfig::SYNCED_TO_YOTPO_CUSTOMER_ATTRIBUTE_NAME, + [ + 'type' => 'int', + 'label' => 'Synced to Yotpo Customer', + 'required' => false, + 'visible' => false, + 'user_defined' => false + ] + ); + return $this; } /**