| @@ -14,8 +14,10 @@ | ||
| 14 | 14 | use Packetery\Module\Framework\WpAdapter; |
| 15 | 15 | use Packetery\Module\Log; |
| 16 | 16 | use Packetery\Module\ModuleHelper; |
| 17 | 17 | use Packetery\Module\Options; |
| 18 | +use Packetery\Module\Options\FlagManager\FeatureFlagNotice; | |
| 19 | +use Packetery\Module\Options\FlagManager\FeatureFlagProvider; | |
| 18 | 20 | use Packetery\Module\Order; |
| 19 | 21 | use Packetery\Module\Order\Metabox; |
| 20 | 22 | use Packetery\Module\Plugin; |
| 21 | 23 | use Packetery\Module\WidgetUrlResolver; |
| @@ -28,8 +30,18 @@ | ||
| 28 | 30 | */ |
| 29 | 31 | private $contextResolver; |
| 30 | 32 | |
| 31 | 33 | /** |
| 34 | + * @var FeatureFlagProvider | |
| 35 | + */ | |
| 36 | + private $featureFlagProvider; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * @var FeatureFlagNotice | |
| 40 | + */ | |
| 41 | + private $featureFlagNotice; | |
| 42 | + | |
| 43 | + /** | |
| 32 | 44 | * @var Metabox |
| 33 | 45 | */ |
| 34 | 46 | private $orderMetabox; |
| 35 | 47 | |
| @@ -64,8 +76,10 @@ | ||
| 64 | 76 | private $widgetUrlResolver; |
| 65 | 77 | |
| 66 | 78 | public function __construct( |
| 67 | 79 | ContextResolver $contextResolver, |
| 80 | + FeatureFlagProvider $featureFlagProvider, | |
| 81 | + FeatureFlagNotice $featureFlagNotice, | |
| 68 | 82 | Metabox $orderMetabox, |
| 69 | 83 | Request $request, |
| 70 | 84 | CheckoutSettings $checkoutSettings, |
| 71 | 85 | WpAdapter $wpAdapter, |
| @@ -72,16 +86,19 @@ | ||
| 72 | 86 | WcAdapter $wcAdapter, |
| 73 | 87 | CheckoutService $checkoutService, |
| 74 | 88 | WidgetUrlResolver $widgetUrlResolver |
| 75 | 89 | ) { |
| 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; | |
| 90 | + | |
| 91 | + $this->contextResolver = $contextResolver; | |
| 92 | + $this->featureFlagProvider = $featureFlagProvider; | |
| 93 | + $this->featureFlagNotice = $featureFlagNotice; | |
| 94 | + $this->orderMetabox = $orderMetabox; | |
| 95 | + $this->request = $request; | |
| 96 | + $this->checkoutSettings = $checkoutSettings; | |
| 97 | + $this->wpAdapter = $wpAdapter; | |
| 98 | + $this->wcAdapter = $wcAdapter; | |
| 99 | + $this->checkoutService = $checkoutService; | |
| 100 | + $this->widgetUrlResolver = $widgetUrlResolver; | |
| 84 | 101 | } |
| 85 | 102 | |
| 86 | 103 | /** |
| 87 | 104 | * Enqueues admin JS file. |
| @@ -119,37 +136,35 @@ | ||
| 119 | 136 | /** |
| 120 | 137 | * Enqueues javascript files and stylesheets for checkout. |
| 121 | 138 | */ |
| 122 | 139 | 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' ); | |
| 140 | + if ( $this->wcAdapter->isCheckout() ) { | |
| 141 | + if ( $this->wpAdapter->doingAjax() === false ) { | |
| 142 | + $this->enqueueStyle( 'packetery-front-styles', 'public/css/front.css' ); | |
| 128 | 143 | |
| 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 ), | |
| 144 | + $customFrontCssPath = WP_CONTENT_DIR . '/packeta-custom-front.css'; | |
| 145 | + if ( file_exists( $customFrontCssPath ) ) { | |
| 146 | + $this->wpAdapter->enqueueStyle( | |
| 147 | + 'packetery-custom-front-styles', | |
| 148 | + $customFrontCssPath, | |
| 149 | + [], | |
| 150 | + md5( (string) filemtime( $customFrontCssPath ) ) | |
| 151 | + ); | |
| 152 | + } | |
| 153 | + } | |
| 154 | + if ( $this->checkoutService->areBlocksUsedInCheckout() ) { | |
| 155 | + $this->wpAdapter->enqueueScript( | |
| 156 | + 'packetery-widget-library', | |
| 157 | + $this->widgetUrlResolver->getUrl(), | |
| 135 | 158 | [], |
| 136 | - md5( (string) filemtime( $customFrontCssPath ) ) | |
| 159 | + Plugin::VERSION, | |
| 160 | + false | |
| 137 | 161 | ); |
| 162 | + } elseif ( $this->wpAdapter->doingAjax() === false ) { | |
| 163 | + $this->enqueueScript( 'packetery-checkout', 'public/js/checkout.js', true, [ 'jquery' ] ); | |
| 164 | + $this->wpAdapter->localizeScript( 'packetery-checkout', 'packeteryCheckoutSettings', $this->checkoutSettings->createSettings() ); | |
| 138 | 165 | } |
| 139 | 166 | } |
| 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 | 167 | } |
| 153 | 168 | |
| 154 | 169 | /** |
| 155 | 170 | * Enqueues javascript files and stylesheets for administration. |
| @@ -213,31 +228,8 @@ | ||
| 213 | 228 | 'jquery', |
| 214 | 229 | 'packetery-select2', |
| 215 | 230 | ] |
| 216 | 231 | ); |
| 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 | 232 | } |
| 241 | 233 | |
| 242 | 234 | $isProductPage = $this->contextResolver->isProductPage(); |
| 243 | 235 | $isPageDetail = $this->contextResolver->isPageDetail(); |
| @@ -259,11 +251,21 @@ | ||
| 259 | 251 | true |
| 260 | 252 | ) |
| 261 | 253 | ) { |
| 262 | 254 | $this->enqueueStyle( 'packetery-admin-styles', 'public/css/admin.css' ); |
| 255 | + // It is placed here so that typenow in contextResolver works and there is no need to repeat the conditions. | |
| 256 | + if ( $this->featureFlagProvider->shouldShowSplitActivationNotice() ) { | |
| 257 | + $this->wpAdapter->addAction( 'admin_notices', [ $this->featureFlagNotice, 'renderSplitActivationNotice' ] ); | |
| 258 | + } | |
| 263 | 259 | } |
| 264 | 260 | |
| 265 | 261 | if ( $isOrderGridPage ) { |
| 262 | + $orderGridPageSettings = [ | |
| 263 | + 'translations' => [ | |
| 264 | + 'hasToFillCustomsDeclaration' => $this->wpAdapter->__( 'Customs declaration has to be filled in order detail.', 'packeta' ), | |
| 265 | + 'packetSubmissionNotPossible' => $this->wpAdapter->__( 'It is not possible to submit the shipment because all the information required for this shipment is not filled.', 'packeta' ), | |
| 266 | + ], | |
| 267 | + ]; | |
| 266 | 268 | $this->enqueueScript( |
| 267 | 269 | 'packetery-admin-grid-order-edit-js', |
| 268 | 270 | 'public/js/admin-grid-order-edit.js', |
| 269 | 271 | true, |
| @@ -274,8 +276,9 @@ | ||
| 274 | 276 | ] |
| 275 | 277 | ); |
| 276 | 278 | |
| 277 | 279 | $this->wpAdapter->localizeScript( 'packetery-admin-grid-order-edit-js', 'datePickerSettings', $datePickerSettings ); |
| 280 | + $this->wpAdapter->localizeScript( 'packetery-admin-grid-order-edit-js', 'settings', $orderGridPageSettings ); | |
| 278 | 281 | |
| 279 | 282 | $this->enqueueScript( |
| 280 | 283 | 'packetery-admin-stored-until-modal-js', |
| 281 | 284 | 'public/js/admin-stored-until-modal.js', |
| @@ -286,8 +289,9 @@ | ||
| 286 | 289 | 'backbone', |
| 287 | 290 | ] |
| 288 | 291 | ); |
| 289 | 292 | $this->wpAdapter->localizeScript( 'packetery-admin-stored-until-modal-js', 'datePickerSettings', $datePickerSettings ); |
| 293 | + $this->wpAdapter->localizeScript( 'packetery-admin-stored-until-modal-js', 'settings', $orderGridPageSettings ); | |
| 290 | 294 | } |
| 291 | 295 | |
| 292 | 296 | $pickupPointPickerSettings = null; |
| 293 | 297 | $addressPickerSettings = null; |