23
23
24
24
use Magento \OfflineShipping \Model \Config \Backend \Tablerate ;
25
25
use Magento \Framework \Exception \FileSystemException ;
26
+ use Magento \Store \Model \StoreManagerInterface ;
26
27
use Meta \BusinessExtension \Model \System \Config as SystemConfig ;
27
28
use Magento \Framework \Filesystem ;
28
29
use Meta \BusinessExtension \Helper \GraphAPIAdapter ;
@@ -57,6 +58,11 @@ class ShippingSettingsUpdatePlugin
57
58
*/
58
59
protected $ systemConfig ;
59
60
61
+ /**
62
+ * @var StoreManagerInterface
63
+ */
64
+ private StoreManagerInterface $ storeManager ;
65
+
60
66
/**
61
67
* Constructor for Shipping settings update plugin
62
68
*
@@ -65,19 +71,22 @@ class ShippingSettingsUpdatePlugin
65
71
* @param GraphAPIAdapter $graphApiAdapter
66
72
* @param FBEHelper $fbeHelper
67
73
* @param SystemConfig $systemConfig
74
+ * @param StoreManagerInterface $storeManager
68
75
*/
69
76
public function __construct (
70
- ShippingDataFactory $ shippingRatesFactory ,
71
- FileSystem $ fileSystem ,
72
- GraphAPIAdapter $ graphApiAdapter ,
73
- FBEHelper $ fbeHelper ,
74
- SystemConfig $ systemConfig
77
+ ShippingDataFactory $ shippingRatesFactory ,
78
+ FileSystem $ fileSystem ,
79
+ GraphAPIAdapter $ graphApiAdapter ,
80
+ FBEHelper $ fbeHelper ,
81
+ SystemConfig $ systemConfig ,
82
+ StoreManagerInterface $ storeManager ,
75
83
) {
76
84
$ this ->shippingRatesFactory = $ shippingRatesFactory ;
77
85
$ this ->fileSystem = $ fileSystem ;
78
86
$ this ->graphApiAdapter = $ graphApiAdapter ;
79
87
$ this ->fbeHelper = $ fbeHelper ;
80
88
$ this ->systemConfig = $ systemConfig ;
89
+ $ this ->storeManager = $ storeManager ;
81
90
}
82
91
83
92
/**
@@ -87,23 +96,27 @@ public function __construct(
87
96
*/
88
97
public function afterSave (): void
89
98
{
90
- try {
91
- $ shippingRates = $ this ->shippingRatesFactory ->create ();
92
- $ fileBuilder = new ShippingFileBuilder ($ this ->fileSystem );
93
- $ shippingProfiles = [
94
- $ shippingRates ->buildTableRatesProfile (),
95
- $ shippingRates ->buildFlatRateProfile (),
96
- $ shippingRates ->buildFreeShippingProfile ()
97
- ];
98
- $ file_uri = $ fileBuilder ->createFile ($ shippingProfiles );
99
- $ partnerIntegrationId = $ this ->systemConfig ->getCommercePartnerIntegrationId ();
100
- $ this ->graphApiAdapter ->uploadFile ($ partnerIntegrationId , $ file_uri , "SHIPPING_PROFILES " , "CREATE " );
101
- } catch (Exception $ e ) {
102
- $ this ->fbeHelper ->logExceptionImmediatelyToMeta ($ e , [
103
- 'store_id ' => $ this ->fbeHelper ->getStore ()->getId (),
104
- 'event ' => 'shipping_profile_sync ' ,
105
- 'event_type ' => 'after_save '
106
- ]);
99
+ foreach ($ this ->storeManager ->getStores () as $ store ) {
100
+ try {
101
+ $ shippingRates = $ this ->shippingRatesFactory ->create ();
102
+ $ fileBuilder = new ShippingFileBuilder ($ this ->fileSystem );
103
+ $ shippingProfiles = [
104
+ $ shippingRates ->buildTableRatesProfile (),
105
+ $ shippingRates ->buildFlatRateProfile (),
106
+ $ shippingRates ->buildFreeShippingProfile ()
107
+ ];
108
+ $ file_uri = $ fileBuilder ->createFile ($ shippingProfiles );
109
+ $ partnerIntegrationId = $ this ->systemConfig ->getCommercePartnerIntegrationId ($ store ->getId ());
110
+ $ this ->graphApiAdapter ->setDebugMode ($ this ->systemConfig ->isDebugMode ($ store ->getId ()))
111
+ ->setAccessToken ($ this ->systemConfig ->getAccessToken ($ store ->getId ()));
112
+ $ this ->graphApiAdapter ->uploadFile ($ partnerIntegrationId , $ file_uri , "SHIPPING_PROFILES " , "CREATE " );
113
+ } catch (Exception $ e ) {
114
+ $ this ->fbeHelper ->logExceptionImmediatelyToMeta ($ e , [
115
+ 'store_id ' => $ this ->fbeHelper ->getStore ()->getId (),
116
+ 'event ' => 'shipping_profile_sync ' ,
117
+ 'event_type ' => 'after_save '
118
+ ]);
119
+ }
107
120
}
108
121
}
109
122
}
0 commit comments