PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | src/Packetery/Module/Views/AssetManager.php +53 -78 trunk2.0.9 View file →
@@ -8,14 +8,15 @@
8 8 use Packetery\Module\Carrier;
9 9 use Packetery\Module\Checkout\CheckoutService;
10 10 use Packetery\Module\Checkout\CheckoutSettings;
11 11 use Packetery\Module\ContextResolver;
12 -use Packetery\Module\Dashboard\DashboardPage;
13 12 use Packetery\Module\Framework\WcAdapter;
14 13 use Packetery\Module\Framework\WpAdapter;
15 14 use Packetery\Module\Log;
16 15 use Packetery\Module\ModuleHelper;
17 16 use Packetery\Module\Options;
17 +use Packetery\Module\Options\FlagManager\FeatureFlagNotice;
18 +use Packetery\Module\Options\FlagManager\FeatureFlagProvider;
18 19 use Packetery\Module\Order;
19 20 use Packetery\Module\Order\Metabox;
20 21 use Packetery\Module\Plugin;
21 22 use Packetery\Module\WidgetUrlResolver;
@@ -28,8 +29,18 @@
28 29 */
29 30 private $contextResolver;
30 31
31 32 /**
33 + * @var FeatureFlagProvider
34 + */
35 + private $featureFlagProvider;
36 +
37 + /**
38 + * @var FeatureFlagNotice
39 + */
40 + private $featureFlagNotice;
41 +
42 + /**
32 43 * @var Metabox
33 44 */
34 45 private $orderMetabox;
35 46
@@ -64,8 +75,10 @@
64 75 private $widgetUrlResolver;
65 76
66 77 public function __construct(
67 78 ContextResolver $contextResolver,
79 + FeatureFlagProvider $featureFlagProvider,
80 + FeatureFlagNotice $featureFlagNotice,
68 81 Metabox $orderMetabox,
69 82 Request $request,
70 83 CheckoutSettings $checkoutSettings,
71 84 WpAdapter $wpAdapter,
@@ -72,16 +85,19 @@
72 85 WcAdapter $wcAdapter,
73 86 CheckoutService $checkoutService,
74 87 WidgetUrlResolver $widgetUrlResolver
75 88 ) {
76 - $this->contextResolver = $contextResolver;
77 - $this->orderMetabox = $orderMetabox;
78 - $this->request = $request;
79 - $this->checkoutSettings = $checkoutSettings;
80 - $this->wpAdapter = $wpAdapter;
81 - $this->wcAdapter = $wcAdapter;
82 - $this->checkoutService = $checkoutService;
83 - $this->widgetUrlResolver = $widgetUrlResolver;
89 +
90 + $this->contextResolver = $contextResolver;
91 + $this->featureFlagProvider = $featureFlagProvider;
92 + $this->featureFlagNotice = $featureFlagNotice;
93 + $this->orderMetabox = $orderMetabox;
94 + $this->request = $request;
95 + $this->checkoutSettings = $checkoutSettings;
96 + $this->wpAdapter = $wpAdapter;
97 + $this->wcAdapter = $wcAdapter;
98 + $this->checkoutService = $checkoutService;
99 + $this->widgetUrlResolver = $widgetUrlResolver;
84 100 }
85 101
86 102 /**
87 103 * Enqueues admin JS file.
@@ -90,9 +106,9 @@
90 106 * @param string $file Relative file path.
91 107 * @param bool $inFooter Tells where to include script.
92 108 * @param array $deps Script dependencies.
93 109 */
94 - public function enqueueScript( string $name, string $file, bool $inFooter, array $deps = [] ): void {
110 + private function enqueueScript( string $name, string $file, bool $inFooter, array $deps = [] ): void {
95 111 $this->wpAdapter->enqueueScript(
96 112 $name,
97 113 $this->wpAdapter->pluginDirUrl( ModuleHelper::getPluginMainFilePath() ) . $file,
98 114 $deps,
@@ -106,9 +122,9 @@
106 122 *
107 123 * @param string $name Name of script.
108 124 * @param string $file Relative file path.
109 125 */
110 - public function enqueueStyle( string $name, string $file ): void {
126 + private function enqueueStyle( string $name, string $file ): void {
111 127 $this->wpAdapter->enqueueStyle(
112 128 $name,
113 129 $this->wpAdapter->pluginDirUrl( ModuleHelper::getPluginMainFilePath() ) . $file,
114 130 [],
@@ -119,37 +135,26 @@
119 135 /**
120 136 * Enqueues javascript files and stylesheets for checkout.
121 137 */
122 138 public function enqueueFrontAssets(): void {
123 - if ( ! $this->wcAdapter->isCheckout() ) {
124 - return;
125 - }
126 - if ( $this->wpAdapter->doingAjax() === false ) {
127 - $this->enqueueStyle( 'packetery-front-styles', 'public/css/front.css' );
128 -
129 - $customFrontCssFilename = 'packeta-custom-front.css';
130 - $customFrontCssPath = WP_CONTENT_DIR . '/' . $customFrontCssFilename;
131 - if ( file_exists( $customFrontCssPath ) ) {
132 - $this->wpAdapter->enqueueStyle(
133 - 'packetery-custom-front-styles',
134 - $this->wpAdapter->contentUrl( $customFrontCssFilename ),
139 + if ( $this->wcAdapter->isCheckout() ) {
140 + if ( $this->wpAdapter->doingAjax() === false ) {
141 + $this->enqueueStyle( 'packetery-front-styles', 'public/css/front.css' );
142 + $this->enqueueStyle( 'packetery-custom-front-styles', 'public/css/custom-front.css' );
143 + }
144 + if ( $this->checkoutService->areBlocksUsedInCheckout() ) {
145 + $this->wpAdapter->enqueueScript(
146 + 'packetery-widget-library',
147 + $this->widgetUrlResolver->getUrl(),
135 148 [],
136 - md5( (string) filemtime( $customFrontCssPath ) )
149 + Plugin::VERSION,
150 + false
137 151 );
152 + } elseif ( $this->wpAdapter->doingAjax() === false ) {
153 + $this->enqueueScript( 'packetery-checkout', 'public/js/checkout.js', true, [ 'jquery' ] );
154 + $this->wpAdapter->localizeScript( 'packetery-checkout', 'packeteryCheckoutSettings', $this->checkoutSettings->createSettings() );
138 155 }
139 156 }
140 - if ( $this->checkoutService->areBlocksUsedInCheckout() ) {
141 - $this->wpAdapter->enqueueScript(
142 - 'packetery-widget-library',
143 - $this->widgetUrlResolver->getUrl(),
144 - [],
145 - Plugin::VERSION,
146 - false
147 - );
148 - } elseif ( $this->wpAdapter->doingAjax() === false ) {
149 - $this->enqueueScript( 'packetery-checkout', 'public/js/checkout.js', true, [ 'jquery' ] );
150 - $this->wpAdapter->localizeScript( 'packetery-checkout', 'packeteryCheckoutSettings', $this->checkoutSettings->createSettings() );
151 - }
152 157 }
153 158
154 159 /**
155 160 * Enqueues javascript files and stylesheets for administration.
@@ -213,31 +218,8 @@
213 218 'jquery',
214 219 'packetery-select2',
215 220 ]
216 221 );
217 -
218 - $this->wpAdapter->localizeScript(
219 - 'packetery-admin-options',
220 - 'translationsAdminOptions',
221 - [
222 - 'confirmLogDeletion' => $this->wpAdapter->__(
223 - 'Are you sure you want to delete the log file?',
224 - 'packeta'
225 - ),
226 - ]
227 - );
228 -
229 - $this->wpAdapter->enqueueEditor();
230 - $this->wpAdapter->enqueueScript( 'editor' );
231 - $this->enqueueScript(
232 - 'packetery-bug-report-editor',
233 - 'public/js/bug-report-editor.js',
234 - true,
235 - [
236 - 'jquery',
237 - 'editor',
238 - ]
239 - );
240 222 }
241 223
242 224 $isProductPage = $this->contextResolver->isProductPage();
243 225 $isPageDetail = $this->contextResolver->isPageDetail();
@@ -253,17 +235,26 @@
253 235 Options\Page::SLUG,
254 236 Carrier\OptionsPage::SLUG,
255 237 Log\Page::SLUG,
256 238 Order\LabelPrint::MENU_SLUG,
257 - DashboardPage::SLUG,
258 239 ],
259 240 true
260 241 )
261 242 ) {
262 243 $this->enqueueStyle( 'packetery-admin-styles', 'public/css/admin.css' );
244 + // It is placed here so that typenow in contextResolver works and there is no need to repeat the conditions.
245 + if ( $this->featureFlagProvider->shouldShowSplitActivationNotice() ) {
246 + $this->wpAdapter->addAction( 'admin_notices', [ $this->featureFlagNotice, 'renderSplitActivationNotice' ] );
247 + }
263 248 }
264 249
265 250 if ( $isOrderGridPage ) {
251 + $orderGridPageSettings = [
252 + 'translations' => [
253 + 'hasToFillCustomsDeclaration' => $this->wpAdapter->__( 'Customs declaration has to be filled in order detail.', 'packeta' ),
254 + 'packetSubmissionNotPossible' => $this->wpAdapter->__( 'It is not possible to submit the shipment because all the information required for this shipment is not filled.', 'packeta' ),
255 + ],
256 + ];
266 257 $this->enqueueScript(
267 258 'packetery-admin-grid-order-edit-js',
268 259 'public/js/admin-grid-order-edit.js',
269 260 true,
@@ -274,8 +265,9 @@
274 265 ]
275 266 );
276 267
277 268 $this->wpAdapter->localizeScript( 'packetery-admin-grid-order-edit-js', 'datePickerSettings', $datePickerSettings );
269 + $this->wpAdapter->localizeScript( 'packetery-admin-grid-order-edit-js', 'settings', $orderGridPageSettings );
278 270
279 271 $this->enqueueScript(
280 272 'packetery-admin-stored-until-modal-js',
281 273 'public/js/admin-stored-until-modal.js',
@@ -286,8 +278,9 @@
286 278 'backbone',
287 279 ]
288 280 );
289 281 $this->wpAdapter->localizeScript( 'packetery-admin-stored-until-modal-js', 'datePickerSettings', $datePickerSettings );
282 + $this->wpAdapter->localizeScript( 'packetery-admin-stored-until-modal-js', 'settings', $orderGridPageSettings );
290 283 }
291 284
292 285 $pickupPointPickerSettings = null;
293 286 $addressPickerSettings = null;
@@ -376,25 +369,7 @@
376 369 }
377 370
378 371 if ( $this->contextResolver->isConfirmModalPage() ) {
379 372 $this->enqueueScript( 'packetery-confirm', 'public/js/confirm.js', true, [ 'jquery', 'backbone' ] );
380 - }
381 - if ( $this->contextResolver->isPluginsOverviewPage() ) {
382 - $this->enqueueScript(
383 - 'packetery-admin-confirm-deactivation',
384 - 'public/js/admin-confirm-deactivation.js',
385 - true
386 - );
387 -
388 - $this->wpAdapter->localizeScript(
389 - 'packetery-admin-confirm-deactivation',
390 - 'translationsDeactivation',
391 - [
392 - 'confirmDeactivation' => $this->wpAdapter->__(
393 - 'When uninstalling the plugin, ALL data and settings will be removed only if the PACKETERY_REMOVE_ALL_DATA constant is defined in wp-config.php and is set to true. This is to prevent data loss when removing the plugin from the backend and to ensure that only the site owner can perform this action.',
394 - 'packeta'
395 - ),
396 - ]
397 - );
398 373 }
399 374 }
400 375 }