PluginProbe
Packeta / 1.6.2
Packeta v1.6.2
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
packeta / src / Packetery / Module / Carrier / OptionsPage.php

OptionsPage.php in Packeta 1.6.2, at src/Packetery/Module/Carrier/OptionsPage.php

670 lines 20.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class OptionsPage
4 *
5 * @package Packetery\Options
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Module\Carrier;
11
12 use Packetery\Core\Entity\Carrier;
13 use Packetery\Core\Helper;
14 use Packetery\Core\Rounder;
15 use Packetery\Module\FormFactory;
16 use Packetery\Module\FormValidators;
17 use Packetery\Module\MessageManager;
18 use Packetery\Module\Options\FeatureFlagManager;
19 use Packetery\Latte\Engine;
20 use Packetery\Module\PaymentGatewayHelper;
21 use Packetery\Nette\Forms\Container;
22 use Packetery\Nette\Forms\Form;
23 use Packetery\Nette\Http\Request;
24
25 /**
26 * Class OptionsPage
27 *
28 * @package Packetery\Options
29 */
30 class OptionsPage {
31
32 public const FORM_FIELD_NAME = 'name';
33 public const SLUG = 'packeta-country';
34 public const MINIMUM_CHECKED_VENDORS = 2;
35
36 /**
37 * PacketeryLatte_engine.
38 *
39 * @var Engine PacketeryLatte engine.
40 */
41 private $latteEngine;
42
43 /**
44 * Carrier repository.
45 *
46 * @var EntityRepository Carrier repository.
47 */
48 private $carrierRepository;
49
50 /**
51 * Form factory.
52 *
53 * @var FormFactory Form factory.
54 */
55 private $formFactory;
56
57 /**
58 * Packetery\Nette Request.
59 *
60 * @var Request Packetery\Nette Request.
61 */
62 private $httpRequest;
63
64 /**
65 * CountryListingPage.
66 *
67 * @var CountryListingPage CountryListingPage.
68 */
69 private $countryListingPage;
70
71 /**
72 * Message manager.
73 *
74 * @var MessageManager
75 */
76 private $messageManager;
77
78 /**
79 * Internal pickup points config.
80 *
81 * @var PacketaPickupPointsConfig
82 */
83 private $pickupPointsConfig;
84
85 /**
86 * Feature flag.
87 *
88 * @var FeatureFlagManager
89 */
90 private $featureFlag;
91
92 /**
93 * Plugin constructor.
94 *
95 * @param Engine $latteEngine PacketeryLatte_engine.
96 * @param EntityRepository $carrierRepository Carrier repository.
97 * @param FormFactory $formFactory Form factory.
98 * @param Request $httpRequest Packetery\Nette Request.
99 * @param CountryListingPage $countryListingPage CountryListingPage.
100 * @param MessageManager $messageManager Message manager.
101 * @param PacketaPickupPointsConfig $pickupPointsConfig Internal pickup points config.
102 * @param FeatureFlagManager $featureFlag Feature flag.
103 */
104 public function __construct(
105 Engine $latteEngine,
106 EntityRepository $carrierRepository,
107 FormFactory $formFactory,
108 Request $httpRequest,
109 CountryListingPage $countryListingPage,
110 MessageManager $messageManager,
111 PacketaPickupPointsConfig $pickupPointsConfig,
112 FeatureFlagManager $featureFlag
113 ) {
114 $this->latteEngine = $latteEngine;
115 $this->carrierRepository = $carrierRepository;
116 $this->formFactory = $formFactory;
117 $this->httpRequest = $httpRequest;
118 $this->countryListingPage = $countryListingPage;
119 $this->messageManager = $messageManager;
120 $this->pickupPointsConfig = $pickupPointsConfig;
121 $this->featureFlag = $featureFlag;
122 }
123
124 /**
125 * Registers WP callbacks.
126 */
127 public function register(): void {
128 add_submenu_page(
129 \Packetery\Module\Options\Page::SLUG,
130 __( 'Carrier settings', 'packeta' ),
131 __( 'Carrier settings', 'packeta' ),
132 'manage_options',
133 self::SLUG,
134 array(
135 $this,
136 'render',
137 ),
138 10
139 );
140 }
141
142 /**
143 * Creates settings form.
144 *
145 * @param array $carrierData Carrier data.
146 *
147 * @return Form
148 */
149 private function createForm( array $carrierData ): Form {
150 $optionId = OptionPrefixer::getOptionId( $carrierData['id'] );
151
152 $form = $this->formFactory->create( $optionId );
153
154 $form->addCheckbox(
155 'active',
156 __( 'Active carrier', 'packeta' ) . ':'
157 );
158
159 $form->addText( self::FORM_FIELD_NAME, __( 'Display name', 'packeta' ) . ':' )
160 ->setRequired();
161
162 $carrierOptions = get_option( $optionId );
163 if ( $this->featureFlag->isSplitActive() ) {
164 $vendorCheckboxes = $this->getVendorCheckboxesConfig( $carrierData['id'], ( $carrierOptions ? $carrierOptions : null ) );
165 if ( $vendorCheckboxes ) {
166 $vendorsContainer = $form->addContainer( 'vendor_groups' );
167 foreach ( $vendorCheckboxes as $checkboxConfig ) {
168 $checkboxControl = $vendorsContainer->addCheckbox( $checkboxConfig['group'], $checkboxConfig['name'] );
169 if ( true === $checkboxConfig['disabled'] ) {
170 $checkboxControl->setDisabled()->setOmitted( false );
171 }
172 if ( true === $checkboxConfig['default'] ) {
173 $checkboxControl->setDefaultValue( true );
174 }
175 }
176 }
177 }
178
179 $weightLimits = $form->addContainer( 'weight_limits' );
180 if ( empty( $carrierData['weight_limits'] ) ) {
181 $this->addWeightLimit( $weightLimits, 0 );
182 } else {
183 foreach ( $carrierData['weight_limits'] as $index => $limit ) {
184 $this->addWeightLimit( $weightLimits, $index );
185 }
186 }
187
188 // We don't expect id to be empty in this situation. This would indicate a data save error.
189 $carrier = $this->carrierRepository->getAnyById( (string) $carrierData['id'] );
190
191 if ( null !== $carrier && $carrier->supportsCod() ) {
192 $form->addText( 'default_COD_surcharge', __( 'Default COD surcharge', 'packeta' ) . ':' )
193 ->setRequired( false )
194 ->addRule( Form::FLOAT )
195 ->addRule( Form::MIN, null, 0 );
196
197 $surchargeLimits = $form->addContainer( 'surcharge_limits' );
198 if ( ! empty( $carrierData['surcharge_limits'] ) ) {
199 foreach ( $carrierData['surcharge_limits'] as $index => $limit ) {
200 $this->addSurchargeLimit( $surchargeLimits, $index );
201 }
202 }
203 $roundingOptions = [
204 Rounder::DONT_ROUND => __( 'No rounding', 'packeta' ),
205 Rounder::ROUND_DOWN => __( 'Always round down', 'packeta' ),
206 Rounder::ROUND_UP => __( 'Always round up', 'packeta' ),
207 ];
208 $form->addSelect( 'cod_rounding', __( 'COD rounding', 'packeta' ) . ':', $roundingOptions )
209 ->setDefaultValue( Rounder::DONT_ROUND );
210 }
211
212 $item = $form->addText( 'free_shipping_limit', __( 'Free shipping limit', 'packeta' ) . ':' );
213 $item->addRule( $form::FLOAT, __( 'Please enter a valid decimal number.', 'packeta' ) );
214
215 $couponFreeShipping = $form->addContainer( 'coupon_free_shipping' );
216 $couponFreeShipping->addCheckbox( 'active', __( 'Apply free shipping coupon', 'packeta' ) );
217 $couponFreeShipping->addCheckbox( 'allow_for_fees', __( 'Apply free shipping coupon for fees', 'packeta' ) )
218 ->addConditionOn( $form['coupon_free_shipping']['active'], Form::FILLED )
219 ->toggle( $this->createCouponFreeShippingForFeesContainerId( $form ) );
220
221 $form->addHidden( 'id' )->setRequired();
222 $form->addSubmit( 'save' );
223
224 if ( false === $carrier->hasPickupPoints() && in_array( $carrier->getCountry(), Carrier::ADDRESS_VALIDATION_COUNTRIES, true ) ) {
225 $addressValidationOptions = [
226 'none' => __( 'No address validation', 'packeta' ),
227 'optional' => __( 'Optional address validation', 'packeta' ),
228 'required' => __( 'Required address validation', 'packeta' ),
229 ];
230 $form->addSelect( 'address_validation', __( 'Address validation', 'packeta' ) . ':', $addressValidationOptions )
231 ->setDefaultValue( 'none' );
232 }
233
234 if ( $carrier->supportsAgeVerification() ) {
235 $form->addText( 'age_verification_fee', __( 'Age verification fee', 'packeta' ) . ':' )
236 ->setRequired( false )
237 ->addRule( Form::FLOAT )
238 ->addRule( Form::MIN, null, 0 );
239 }
240
241 $form->addMultiSelect(
242 'disallowed_checkout_payment_methods',
243 __( 'Disallowed checkout payment methods', 'packeta' ),
244 PaymentGatewayHelper::getAvailablePaymentGatewayChoices()
245 )->checkDefaultValue( false );
246
247 $form->onValidate[] = [ $this, 'validateOptions' ];
248 $form->onSuccess[] = [ $this, 'updateOptions' ];
249
250 if ( false === $carrierOptions ) {
251 $carrierOptions = [
252 'id' => $carrierData['id'],
253 self::FORM_FIELD_NAME => $carrierData['name'],
254 ];
255 }
256 $form->setDefaults( $carrierOptions );
257
258 return $form;
259 }
260
261 /**
262 * Creates form toggle ID for coupon free shipping.
263 *
264 * @param Form $form Form.
265 *
266 * @return string
267 */
268 private function createCouponFreeShippingForFeesContainerId( Form $form ): string {
269 return sprintf( '%s_apply_free_shipping_coupon_allow_for_fees', $form->getName() );
270 }
271
272 /**
273 * Creates settings form.
274 *
275 * @param array $carrierData Carrier data.
276 *
277 * @return Form
278 */
279 private function createFormTemplate( array $carrierData ): Form {
280 $optionId = OptionPrefixer::getOptionId( $carrierData['id'] );
281
282 $form = $this->formFactory->create( $optionId . '_template' );
283
284 $weightLimitsTemplate = $form->addContainer( 'weight_limits' );
285 $this->addWeightLimit( $weightLimitsTemplate, 0 );
286
287 $surchargeLimitsTemplate = $form->addContainer( 'surcharge_limits' );
288 $this->addSurchargeLimit( $surchargeLimitsTemplate, 0 );
289
290 return $form;
291 }
292
293 /**
294 * Validates options.
295 *
296 * @param Form $form Form.
297 */
298 public function validateOptions( Form $form ): void {
299 if ( $form->hasErrors() ) {
300 add_settings_error( '', '', esc_attr( __( 'Some carrier data is invalid', 'packeta' ) ) );
301 return;
302 }
303
304 $options = $form->getValues( 'array' );
305
306 if ( $this->featureFlag->isSplitActive() ) {
307 $checkedVendors = $this->getCheckedVendors( $options );
308 if (
309 isset( $options['vendor_groups'] ) &&
310 count( $options['vendor_groups'] ) >= self::MINIMUM_CHECKED_VENDORS &&
311 count( $checkedVendors ) < self::MINIMUM_CHECKED_VENDORS
312 ) {
313 $vendorMessage = __( 'Check at least two types of pickup points or use a carrier which delivers to the desired pickup point type.', 'packeta' );
314 add_settings_error( 'vendor_groups', 'vendor_groups', esc_attr( $vendorMessage ) );
315 $form->addError( $vendorMessage );
316 }
317 }
318
319 $this->checkOverlapping(
320 $form,
321 $options,
322 'weight_limits',
323 'weight',
324 __( 'Weight rules are overlapping, please fix them.', 'packeta' )
325 );
326 if ( isset( $options['surcharge_limits'] ) ) {
327 $this->checkOverlapping(
328 $form,
329 $options,
330 'surcharge_limits',
331 'order_price',
332 __( 'Surcharge rules are overlapping, please fix them.', 'packeta' )
333 );
334 }
335 }
336
337 /**
338 * Saves carrier options. onSuccess callback.
339 *
340 * @param Form $form Form.
341 *
342 * @return void
343 */
344 public function updateOptions( Form $form ): void {
345 $options = $form->getValues( 'array' );
346 $newVendors = $this->getCheckedVendors( $options );
347 if ( $newVendors ) {
348 $options['vendor_groups'] = $newVendors;
349 }
350
351 $options = $this->mergeNewLimits( $options, 'weight_limits' );
352 $options = $this->sortLimits( $options, 'weight_limits', 'weight' );
353 if ( isset( $options['surcharge_limits'] ) ) {
354 $options = $this->mergeNewLimits( $options, 'surcharge_limits' );
355 $options = $this->sortLimits( $options, 'surcharge_limits', 'order_price' );
356 }
357
358 update_option( OptionPrefixer::getOptionId( $options['id'] ), $options );
359 $this->messageManager->flash_message( __( 'Settings saved', 'packeta' ), MessageManager::TYPE_SUCCESS, MessageManager::RENDERER_PACKETERY, 'carrier-country' );
360
361 if ( wp_safe_redirect(
362 add_query_arg(
363 [
364 'page' => self::SLUG,
365 'code' => $this->httpRequest->getQuery( 'code' ),
366 ],
367 get_admin_url( null, 'admin.php' )
368 ),
369 303
370 ) ) {
371 exit;
372 }
373 }
374
375 /**
376 * Renders page.
377 */
378 public function render(): void {
379 $countryIso = $this->httpRequest->getQuery( 'code' );
380 if ( $countryIso ) {
381 $countryCarriers = $this->carrierRepository->getByCountryIncludingNonFeed( $countryIso );
382 $carriersData = [];
383 $post = $this->httpRequest->getPost();
384 foreach ( $countryCarriers as $carrier ) {
385 if ( ! empty( $post ) && $post['id'] === $carrier->getId() ) {
386 $formTemplate = $this->createFormTemplate( $post );
387 $form = $this->createForm( $post );
388 if ( $form->isSubmitted() ) {
389 $form->fireEvents();
390 }
391 } else {
392 $carrierData = $carrier->__toArray();
393 $options = get_option( OptionPrefixer::getOptionId( $carrier->getId() ) );
394 if ( false !== $options ) {
395 $carrierData += $options;
396 }
397 $formTemplate = $this->createFormTemplate( $carrierData );
398 $form = $this->createForm( $carrierData );
399 }
400
401 $carriersData[] = [
402 'form' => $form,
403 'formTemplate' => $formTemplate,
404 'carrier' => $carrier,
405 'couponFreeShippingForFeesContainerId' => $this->createCouponFreeShippingForFeesContainerId( $form ),
406 ];
407 }
408
409 $this->latteEngine->render(
410 PACKETERY_PLUGIN_DIR . '/template/carrier/country.latte',
411 [
412 'forms' => $carriersData,
413 'country_iso' => $countryIso,
414 'globalCurrency' => get_woocommerce_currency_symbol(),
415 'flashMessages' => $this->messageManager->renderToString( MessageManager::RENDERER_PACKETERY, 'carrier-country' ),
416 'translations' => [
417 'cannotUseThisCarrierBecauseRequiresCustomsDeclaration' => __( 'This carrier cannot be used, because it requires a customs declaration.', 'packeta' ),
418 'delete' => __( 'Delete', 'packeta' ),
419 'weightRules' => __( 'Weight rules', 'packeta' ),
420 'addWeightRule' => __( 'Add weight rule', 'packeta' ),
421 'codSurchargeRules' => __( 'COD surcharge rules', 'packeta' ),
422 'addCodSurchargeRule' => __( 'Add COD surcharge rule', 'packeta' ),
423 'afterExceedingThisAmountShippingIsFree' => __( 'After exceeding this amount, shipping is free.', 'packeta' ),
424 'addressValidationDescription' => __( 'Customer address validation.', 'packeta' ),
425 'roundingDescription' => __( 'COD rounding for submitting data to Packeta', 'packeta' ),
426 'saveChanges' => __( 'Save changes', 'packeta' ),
427 'packeta' => __( 'Packeta', 'packeta' ),
428 // translators: %s is country code.
429 'title' => sprintf( __( 'Country options: %s', 'packeta' ), strtoupper( $countryIso ) ),
430
431 'noKnownCarrierForThisCountry' => __( 'No carriers available for this country.', 'packeta' ),
432 'ageVerificationSupportedNotification' => __( 'When shipping via this carrier, you can order the Age Verification service. The service will get ordered automatically if there is at least 1 product in the order with the age verification setting.', 'packeta' ),
433 'carrierDoesNotSupportCod' => __( 'This carrier does not support COD payment.', 'packeta' ),
434 'allowedPickupPointTypes' => __( 'Pickup point types.', 'packeta' ),
435 'checkAtLeastTwo' => __( 'Check at least two types of pickup points or use a carrier which delivers to the desired pickup point type.', 'packeta' ),
436 ],
437 ]
438 );
439 } else {
440 $this->countryListingPage->render();
441 }
442 }
443
444 /**
445 * Transforms new_ keys to common numeric.
446 *
447 * @param array $options Options to merge.
448 * @param string $limitsContainer Container id.
449 *
450 * @return array
451 */
452 private function mergeNewLimits( array $options, string $limitsContainer ): array {
453 $newOptions = [];
454 if ( isset( $options[ $limitsContainer ] ) ) {
455 foreach ( $options[ $limitsContainer ] as $key => $option ) {
456 if ( is_int( $key ) ) {
457 $newOptions[ $key ] = $option;
458 }
459 if ( 0 === strpos( (string) $key, 'new_' ) ) {
460 $newOptions[] = $option;
461 }
462 }
463 $options[ $limitsContainer ] = $newOptions;
464 }
465
466 return $options;
467 }
468
469 /**
470 * Checks rules overlapping.
471 *
472 * @param Form $form Form.
473 * @param array $options Form data.
474 * @param string $limitsContainer Container id.
475 * @param string $limitKey Rule id.
476 * @param string $overlappingMessage Error message.
477 *
478 * @return void
479 */
480 private function checkOverlapping( Form $form, array $options, string $limitsContainer, string $limitKey, string $overlappingMessage ): void {
481 $limits = array_column( $options[ $limitsContainer ], $limitKey );
482 if ( count( array_unique( $limits, SORT_NUMERIC ) ) !== count( $limits ) ) {
483 add_settings_error( $limitsContainer, $limitsContainer, esc_attr( $overlappingMessage ) );
484 $form->addError( $overlappingMessage );
485 }
486 }
487
488 /**
489 * Sorts rules.
490 *
491 * @param array $options Form data.
492 * @param string $limitsContainer Container id.
493 * @param string $limitKey Rule id.
494 *
495 * @return array
496 */
497 private function sortLimits( array $options, string $limitsContainer, string $limitKey ): array {
498 $limits = array_column( $options[ $limitsContainer ], $limitKey );
499 array_multisort( $limits, SORT_ASC, $options[ $limitsContainer ] );
500
501 return $options;
502 }
503
504 /**
505 * Adds limit fields to form.
506 *
507 * @param Container $weightLimits Container.
508 * @param int|string $index Index.
509 *
510 * @return void
511 */
512 private function addWeightLimit( Container $weightLimits, $index ): void {
513 $limit = $weightLimits->addContainer( (string) $index );
514 $item = $limit->addText( 'weight', __( 'Weight up to', 'packeta' ) . ':' );
515 $item->setRequired();
516 $item->addRule( Form::FLOAT, __( 'Please enter a valid decimal number.', 'packeta' ) );
517 // translators: %d is numeric threshold.
518 $item->addRule( [ FormValidators::class, 'greaterThan' ], __( 'Enter number greater than %d', 'packeta' ), 0.0 );
519
520 $item->addFilter(
521 function ( float $value ) {
522 return Helper::simplifyWeight( $value );
523 }
524 );
525 // translators: %d is numeric threshold.
526 $item->addRule( [ FormValidators::class, 'greaterThan' ], __( 'Enter number greater than %d', 'packeta' ), 0.0 );
527
528 $item = $limit->addText( 'price', __( 'Price', 'packeta' ) . ':' );
529 $item->setRequired();
530 $item->addRule( Form::FLOAT, __( 'Please enter a valid decimal number.', 'packeta' ) );
531 $item->addRule( Form::MIN, null, 0 );
532 }
533
534 /**
535 * Adds limit fields to form.
536 *
537 * @param Container $surchargeLimits Container.
538 * @param int|string $index Index.
539 *
540 * @return void
541 */
542 private function addSurchargeLimit( Container $surchargeLimits, $index ): void {
543 $limit = $surchargeLimits->addContainer( (string) $index );
544 $item = $limit->addText( 'order_price', __( 'Order price up to', 'packeta' ) . ':' );
545 $item->setRequired();
546 $item->addRule( Form::FLOAT, __( 'Please enter a valid decimal number.', 'packeta' ) );
547 $item->addRule( Form::MIN, null, 0 );
548 $item->addCondition( Form::MAX, 0 )
549 ->addCondition( Form::MIN, 0 )
550 // translators: %d is the value.
551 ->addRule( Form::BLANK, __( 'Value must not be %d', 'packeta' ), 0 );
552
553 $item = $limit->addText( 'surcharge', __( 'Surcharge', 'packeta' ) . ':' );
554 $item->setRequired();
555 $item->addRule( Form::FLOAT, __( 'Please enter a valid decimal number.', 'packeta' ) );
556 $item->addRule( Form::MIN, null, 0 );
557 }
558
559 /**
560 * Creates link to page.
561 *
562 * @param string|null $countryCode Country code.
563 *
564 * @return string
565 */
566 public function createUrl( ?string $countryCode = null ): string {
567 $params = [
568 'page' => self::SLUG,
569 ];
570
571 if ( null !== $countryCode ) {
572 $params['code'] = $countryCode;
573 }
574
575 return add_query_arg(
576 $params,
577 admin_url( 'admin.php' )
578 );
579 }
580
581 /**
582 * Gets checked vendors.
583 *
584 * @param array $options Form options.
585 *
586 * @return array
587 */
588 private function getCheckedVendors( array $options ): array {
589 $vendorCodes = [];
590 if ( ! empty( $options['vendor_groups'] ) ) {
591 $vendorCodes = $options['vendor_groups'];
592 }
593
594 $newVendors = [];
595 foreach ( $vendorCodes as $vendorId => $isChecked ) {
596 if ( ! $isChecked ) {
597 continue;
598 }
599 $newVendors[] = $vendorId;
600 }
601
602 return $newVendors;
603 }
604
605 /**
606 * Gets available vendors for compound carrier.
607 *
608 * @param string $id Compound carrier id.
609 *
610 * @return array|null
611 */
612 private function getAvailableVendors( $id ): ?array {
613 if ( ! $this->pickupPointsConfig->isCompoundCarrierId( $id ) ) {
614 return null;
615 }
616
617 $compoundCarriers = $this->pickupPointsConfig->getCompoundCarriers();
618 foreach ( $compoundCarriers as $compoundCarrier ) {
619 if ( $id === $compoundCarrier->getId() ) {
620 return $compoundCarrier->getVendorCodes();
621 }
622 }
623
624 return null;
625 }
626
627 /**
628 * Gets configuration of vendor checkboxes.
629 *
630 * @param string $carrierId Carrier id.
631 * @param array|null $carrierOptions Carrier options.
632 *
633 * @return array
634 */
635 private function getVendorCheckboxesConfig( string $carrierId, ?array $carrierOptions ): array {
636 $availableVendors = $this->getAvailableVendors( $carrierId );
637 if ( null === $availableVendors ) {
638 return [];
639 }
640
641 $vendorCheckboxes = [];
642 $vendorCarriers = $this->pickupPointsConfig->getVendorCarriers();
643 foreach ( $availableVendors as $vendorId ) {
644 $vendorProvider = $vendorCarriers[ $vendorId ];
645 $checkbox = [
646 'group' => $vendorProvider->getGroup(),
647 'name' => $vendorProvider->getName(),
648 'disabled' => null,
649 'default' => null,
650 ];
651 $hasLowCountAvailable = count( $availableVendors ) <= self::MINIMUM_CHECKED_VENDORS;
652 if ( $hasLowCountAvailable ) {
653 $checkbox['disabled'] = true;
654 }
655 $hasGroupSettingsSaved = isset( $carrierOptions['vendor_groups'] );
656 $hasTheGroupAllowed = (
657 $hasGroupSettingsSaved &&
658 in_array( $vendorProvider->getGroup(), $carrierOptions['vendor_groups'], true )
659 );
660 if ( ! $hasGroupSettingsSaved || $hasLowCountAvailable || $hasTheGroupAllowed ) {
661 $checkbox['default'] = true;
662 }
663 $vendorCheckboxes[] = $checkbox;
664 }
665
666 return $vendorCheckboxes;
667 }
668
669 }
670