Move Template implementation classes to internal namespace (#41170)

* Move Template implementation classes to internal namespace

* Fix namespaces that were changed by mistake

* Add missing imports to files since they were moved to another namespace

* Adapt to new lint rules
This commit is contained in:
Nathan Silveira 2023-11-09 16:21:33 -03:00 committed by GitHub
parent daaab7acc8
commit 7b0ef3db00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 452 additions and 438 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: tweak
Move Template implementation classes to internal namespace

View File

@ -6,8 +6,8 @@
namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor; namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor;
use Automattic\WooCommerce\Admin\Features\Features; use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\SimpleProductTemplate; use Automattic\WooCommerce\Internal\Admin\Features\ProductBlockEditor\ProductTemplates\SimpleProductTemplate;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductVariationTemplate; use Automattic\WooCommerce\Internal\Admin\Features\ProductBlockEditor\ProductTemplates\ProductVariationTemplate;
use Automattic\WooCommerce\Admin\PageController; use Automattic\WooCommerce\Admin\PageController;
use Automattic\WooCommerce\Internal\Admin\BlockTemplateRegistry\BlockTemplateRegistry; use Automattic\WooCommerce\Internal\Admin\BlockTemplateRegistry\BlockTemplateRegistry;
use WP_Block_Editor_Context; use WP_Block_Editor_Context;

View File

@ -1,8 +1,11 @@
<?php <?php
namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates; namespace Automattic\WooCommerce\Internal\Admin\Features\ProductBlockEditor\ProductTemplates;
use Automattic\WooCommerce\Admin\BlockTemplates\BlockInterface; use Automattic\WooCommerce\Admin\BlockTemplates\BlockInterface;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\GroupInterface;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductFormTemplateInterface;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\SectionInterface;
use Automattic\WooCommerce\Internal\Admin\BlockTemplates\AbstractBlockTemplate; use Automattic\WooCommerce\Internal\Admin\BlockTemplates\AbstractBlockTemplate;
/** /**

View File

@ -3,10 +3,12 @@
* WooCommerce Product Group Block class. * WooCommerce Product Group Block class.
*/ */
namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates; namespace Automattic\WooCommerce\Internal\Admin\Features\ProductBlockEditor\ProductTemplates;
use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface; use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface;
use Automattic\WooCommerce\Admin\BlockTemplates\ContainerInterface; use Automattic\WooCommerce\Admin\BlockTemplates\ContainerInterface;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\GroupInterface;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\SectionInterface;
use Automattic\WooCommerce\Internal\Admin\BlockTemplates\BlockContainerTrait; use Automattic\WooCommerce\Internal\Admin\BlockTemplates\BlockContainerTrait;
/** /**
@ -14,7 +16,7 @@ use Automattic\WooCommerce\Internal\Admin\BlockTemplates\BlockContainerTrait;
*/ */
class Group extends ProductBlock implements GroupInterface { class Group extends ProductBlock implements GroupInterface {
use BlockContainerTrait; use BlockContainerTrait;
// phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
/** /**
* Group Block constructor. * Group Block constructor.
* *
@ -31,11 +33,12 @@ class Group extends ProductBlock implements GroupInterface {
throw new \InvalidArgumentException( 'Unexpected key "blockName", this defaults to "woocommerce/product-tab".' ); throw new \InvalidArgumentException( 'Unexpected key "blockName", this defaults to "woocommerce/product-tab".' );
} }
if ( $config['id'] && ( empty( $config['attributes'] ) || empty( $config['attributes']['id'] ) ) ) { if ( $config['id'] && ( empty( $config['attributes'] ) || empty( $config['attributes']['id'] ) ) ) {
$config['attributes'] = empty( $config['attributes'] ) ? [] : $config['attributes']; $config['attributes'] = empty( $config['attributes'] ) ? array() : $config['attributes'];
$config['attributes']['id'] = $config['id']; $config['attributes']['id'] = $config['id'];
} }
parent::__construct( array_merge( array( 'blockName' => 'woocommerce/product-tab' ), $config ), $root_template, $parent ); parent::__construct( array_merge( array( 'blockName' => 'woocommerce/product-tab' ), $config ), $root_template, $parent );
} }
// phpcs:enable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
/** /**
* Add a section block type to this template. * Add a section block type to this template.

View File

@ -3,7 +3,7 @@
* WooCommerce Product Block class. * WooCommerce Product Block class.
*/ */
namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates; namespace Automattic\WooCommerce\Internal\Admin\Features\ProductBlockEditor\ProductTemplates;
use Automattic\WooCommerce\Admin\BlockTemplates\BlockInterface; use Automattic\WooCommerce\Admin\BlockTemplates\BlockInterface;
use Automattic\WooCommerce\Admin\BlockTemplates\ContainerInterface; use Automattic\WooCommerce\Admin\BlockTemplates\ContainerInterface;

View File

@ -3,9 +3,10 @@
* ProductVariationTemplate * ProductVariationTemplate
*/ */
namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates; namespace Automattic\WooCommerce\Internal\Admin\Features\ProductBlockEditor\ProductTemplates;
use Automattic\WooCommerce\Admin\Features\Features; use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductFormTemplateInterface;
/** /**
* Simple Product Template. * Simple Product Template.
@ -63,40 +64,40 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
*/ */
private function add_group_blocks() { private function add_group_blocks() {
$this->add_group( $this->add_group(
[ array(
'id' => $this::GROUP_IDS['GENERAL'], 'id' => $this::GROUP_IDS['GENERAL'],
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'title' => __( 'General', 'woocommerce' ), 'title' => __( 'General', 'woocommerce' ),
], ),
] )
); );
$this->add_group( $this->add_group(
[ array(
'id' => $this::GROUP_IDS['PRICING'], 'id' => $this::GROUP_IDS['PRICING'],
'order' => 20, 'order' => 20,
'attributes' => [ 'attributes' => array(
'title' => __( 'Pricing', 'woocommerce' ), 'title' => __( 'Pricing', 'woocommerce' ),
], ),
] )
); );
$this->add_group( $this->add_group(
[ array(
'id' => $this::GROUP_IDS['INVENTORY'], 'id' => $this::GROUP_IDS['INVENTORY'],
'order' => 30, 'order' => 30,
'attributes' => [ 'attributes' => array(
'title' => __( 'Inventory', 'woocommerce' ), 'title' => __( 'Inventory', 'woocommerce' ),
], ),
] )
); );
$this->add_group( $this->add_group(
[ array(
'id' => $this::GROUP_IDS['SHIPPING'], 'id' => $this::GROUP_IDS['SHIPPING'],
'order' => 40, 'order' => 40,
'attributes' => [ 'attributes' => array(
'title' => __( 'Shipping', 'woocommerce' ), 'title' => __( 'Shipping', 'woocommerce' ),
], ),
] )
); );
} }
@ -106,61 +107,61 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
private function add_general_group_blocks() { private function add_general_group_blocks() {
$general_group = $this->get_group_by_id( $this::GROUP_IDS['GENERAL'] ); $general_group = $this->get_group_by_id( $this::GROUP_IDS['GENERAL'] );
$general_group->add_block( $general_group->add_block(
[ array(
'id' => 'general-single-variation-notice', 'id' => 'general-single-variation-notice',
'blockName' => 'woocommerce/product-single-variation-notice', 'blockName' => 'woocommerce/product-single-variation-notice',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'content' => __( '<strong>Youre editing details specific to this variation.</strong> Some information, like description and images, will be inherited from the main product, <noticeLink><parentProductName/></noticeLink>.', 'woocommerce' ), 'content' => __( '<strong>Youre editing details specific to this variation.</strong> Some information, like description and images, will be inherited from the main product, <noticeLink><parentProductName/></noticeLink>.', 'woocommerce' ),
'type' => 'info', 'type' => 'info',
'isDismissible' => true, 'isDismissible' => true,
'name' => $this::SINGLE_VARIATION_NOTICE_DISMISSED_OPTION, 'name' => $this::SINGLE_VARIATION_NOTICE_DISMISSED_OPTION,
], ),
] )
); );
// Basic Details Section. // Basic Details Section.
$basic_details = $general_group->add_section( $basic_details = $general_group->add_section(
[ array(
'id' => 'product-variation-details-section', 'id' => 'product-variation-details-section',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'title' => __( 'Variation details', 'woocommerce' ), 'title' => __( 'Variation details', 'woocommerce' ),
'description' => __( 'This info will be displayed on the product page, category pages, social media, and search results.', 'woocommerce' ), 'description' => __( 'This info will be displayed on the product page, category pages, social media, and search results.', 'woocommerce' ),
], ),
] )
); );
$basic_details->add_block( $basic_details->add_block(
[ array(
'id' => 'product-variation-note', 'id' => 'product-variation-note',
'blockName' => 'woocommerce/product-summary-field', 'blockName' => 'woocommerce/product-summary-field',
'order' => 20, 'order' => 20,
'attributes' => [ 'attributes' => array(
'property' => 'description', 'property' => 'description',
'label' => __( 'Note <optional />', 'woocommerce' ), 'label' => __( 'Note <optional />', 'woocommerce' ),
'helpText' => 'Enter an optional note displayed on the product page when customers select this variation.', 'helpText' => 'Enter an optional note displayed on the product page when customers select this variation.',
], ),
] )
); );
$basic_details->add_block( $basic_details->add_block(
[ array(
'id' => 'product-variation-visibility', 'id' => 'product-variation-visibility',
'blockName' => 'woocommerce/product-checkbox-field', 'blockName' => 'woocommerce/product-checkbox-field',
'order' => 30, 'order' => 30,
'attributes' => [ 'attributes' => array(
'property' => 'status', 'property' => 'status',
'label' => __( 'Hide in product catalog', 'woocommerce' ), 'label' => __( 'Hide in product catalog', 'woocommerce' ),
'checkedValue' => 'private', 'checkedValue' => 'private',
'uncheckedValue' => 'publish', 'uncheckedValue' => 'publish',
], ),
] )
); );
// Images section. // Images section.
$images_section = $general_group->add_section( $images_section = $general_group->add_section(
[ array(
'id' => 'product-variation-images-section', 'id' => 'product-variation-images-section',
'order' => 30, 'order' => 30,
'attributes' => [ 'attributes' => array(
'title' => __( 'Image', 'woocommerce' ), 'title' => __( 'Image', 'woocommerce' ),
'description' => sprintf( 'description' => sprintf(
/* translators: %1$s: Images guide link opening tag. %2$s: Images guide link closing tag. */ /* translators: %1$s: Images guide link opening tag. %2$s: Images guide link closing tag. */
@ -168,38 +169,38 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
'<a href="https://woocommerce.com/posts/how-to-take-professional-product-photos-top-tips" target="_blank" rel="noreferrer">', '<a href="https://woocommerce.com/posts/how-to-take-professional-product-photos-top-tips" target="_blank" rel="noreferrer">',
'</a>' '</a>'
), ),
], ),
] )
); );
$images_section->add_block( $images_section->add_block(
[ array(
'id' => 'product-variation-image', 'id' => 'product-variation-image',
'blockName' => 'woocommerce/product-images-field', 'blockName' => 'woocommerce/product-images-field',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'property' => 'image', 'property' => 'image',
'multiple' => false, 'multiple' => false,
], ),
] )
); );
// Downloads section. // Downloads section.
if ( Features::is_enabled( 'product-virtual-downloadable' ) ) { if ( Features::is_enabled( 'product-virtual-downloadable' ) ) {
$general_group->add_section( $general_group->add_section(
[ array(
'id' => 'product-variation-downloads-section', 'id' => 'product-variation-downloads-section',
'order' => 40, 'order' => 40,
'attributes' => [ 'attributes' => array(
'title' => __( 'Downloads', 'woocommerce' ), 'title' => __( 'Downloads', 'woocommerce' ),
'description' => __( "Add any files you'd like to make available for the customer to download after purchasing, such as instructions or warranty info.", 'woocommerce' ), 'description' => __( "Add any files you'd like to make available for the customer to download after purchasing, such as instructions or warranty info.", 'woocommerce' ),
], ),
] )
)->add_block( )->add_block(
[ array(
'id' => 'product-variation-downloads', 'id' => 'product-variation-downloads',
'blockName' => 'woocommerce/product-downloads-field', 'blockName' => 'woocommerce/product-downloads-field',
'order' => 10, 'order' => 10,
] )
); );
} }
} }
@ -210,24 +211,24 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
private function add_pricing_group_blocks() { private function add_pricing_group_blocks() {
$pricing_group = $this->get_group_by_id( $this::GROUP_IDS['PRICING'] ); $pricing_group = $this->get_group_by_id( $this::GROUP_IDS['PRICING'] );
$pricing_group->add_block( $pricing_group->add_block(
[ array(
'id' => 'pricing-single-variation-notice', 'id' => 'pricing-single-variation-notice',
'blockName' => 'woocommerce/product-single-variation-notice', 'blockName' => 'woocommerce/product-single-variation-notice',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'content' => __( '<strong>Youre editing details specific to this variation.</strong> Some information, like description and images, will be inherited from the main product, <noticeLink><parentProductName/></noticeLink>.', 'woocommerce' ), 'content' => __( '<strong>Youre editing details specific to this variation.</strong> Some information, like description and images, will be inherited from the main product, <noticeLink><parentProductName/></noticeLink>.', 'woocommerce' ),
'type' => 'info', 'type' => 'info',
'isDismissible' => true, 'isDismissible' => true,
'name' => $this::SINGLE_VARIATION_NOTICE_DISMISSED_OPTION, 'name' => $this::SINGLE_VARIATION_NOTICE_DISMISSED_OPTION,
], ),
] )
); );
// Product Pricing Section. // Product Pricing Section.
$product_pricing_section = $pricing_group->add_section( $product_pricing_section = $pricing_group->add_section(
[ array(
'id' => 'product-pricing-section', 'id' => 'product-pricing-section',
'order' => 20, 'order' => 20,
'attributes' => [ 'attributes' => array(
'title' => __( 'Pricing', 'woocommerce' ), 'title' => __( 'Pricing', 'woocommerce' ),
'description' => sprintf( 'description' => sprintf(
/* translators: %1$s: Images guide link opening tag. %2$s: Images guide link closing tag.*/ /* translators: %1$s: Images guide link opening tag. %2$s: Images guide link closing tag.*/
@ -236,72 +237,72 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
'</a>' '</a>'
), ),
'blockGap' => 'unit-40', 'blockGap' => 'unit-40',
], ),
] )
); );
$pricing_columns = $product_pricing_section->add_block( $pricing_columns = $product_pricing_section->add_block(
[ array(
'id' => 'product-pricing-group-pricing-columns', 'id' => 'product-pricing-group-pricing-columns',
'blockName' => 'core/columns', 'blockName' => 'core/columns',
'order' => 10, 'order' => 10,
] )
); );
$pricing_column_1 = $pricing_columns->add_block( $pricing_column_1 = $pricing_columns->add_block(
[ array(
'id' => 'product-pricing-group-pricing-column-1', 'id' => 'product-pricing-group-pricing-column-1',
'blockName' => 'core/column', 'blockName' => 'core/column',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'templateLock' => 'all', 'templateLock' => 'all',
], ),
] )
); );
$pricing_column_1->add_block( $pricing_column_1->add_block(
[ array(
'id' => 'product-pricing-regular-price', 'id' => 'product-pricing-regular-price',
'blockName' => 'woocommerce/product-regular-price-field', 'blockName' => 'woocommerce/product-regular-price-field',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'name' => 'regular_price', 'name' => 'regular_price',
'label' => __( 'Regular price', 'woocommerce' ), 'label' => __( 'Regular price', 'woocommerce' ),
'isRequired' => true, 'isRequired' => true,
], ),
] )
); );
$pricing_column_2 = $pricing_columns->add_block( $pricing_column_2 = $pricing_columns->add_block(
[ array(
'id' => 'product-pricing-group-pricing-column-2', 'id' => 'product-pricing-group-pricing-column-2',
'blockName' => 'core/column', 'blockName' => 'core/column',
'order' => 20, 'order' => 20,
'attributes' => [ 'attributes' => array(
'templateLock' => 'all', 'templateLock' => 'all',
], ),
] )
); );
$pricing_column_2->add_block( $pricing_column_2->add_block(
[ array(
'id' => 'product-pricing-sale-price', 'id' => 'product-pricing-sale-price',
'blockName' => 'woocommerce/product-sale-price-field', 'blockName' => 'woocommerce/product-sale-price-field',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'label' => __( 'Sale price', 'woocommerce' ), 'label' => __( 'Sale price', 'woocommerce' ),
], ),
] )
); );
$product_pricing_section->add_block( $product_pricing_section->add_block(
[ array(
'id' => 'product-pricing-schedule-sale-fields', 'id' => 'product-pricing-schedule-sale-fields',
'blockName' => 'woocommerce/product-schedule-sale-fields', 'blockName' => 'woocommerce/product-schedule-sale-fields',
'order' => 20, 'order' => 20,
] )
); );
$product_pricing_section->add_block( $product_pricing_section->add_block(
[ array(
'id' => 'product-tax-class', 'id' => 'product-tax-class',
'blockName' => 'woocommerce/product-radio-field', 'blockName' => 'woocommerce/product-radio-field',
'order' => 40, 'order' => 40,
'attributes' => [ 'attributes' => array(
'title' => __( 'Tax class', 'woocommerce' ), 'title' => __( 'Tax class', 'woocommerce' ),
'description' => sprintf( 'description' => sprintf(
/* translators: %1$s: Learn more link opening tag. %2$s: Learn more link closing tag.*/ /* translators: %1$s: Learn more link opening tag. %2$s: Learn more link closing tag.*/
@ -310,26 +311,26 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
'</a>' '</a>'
), ),
'property' => 'tax_class', 'property' => 'tax_class',
'options' => [ 'options' => array(
[ array(
'label' => __( 'Same as main product', 'woocommerce' ), 'label' => __( 'Same as main product', 'woocommerce' ),
'value' => 'parent', 'value' => 'parent',
], ),
[ array(
'label' => __( 'Standard', 'woocommerce' ), 'label' => __( 'Standard', 'woocommerce' ),
'value' => '', 'value' => '',
], ),
[ array(
'label' => __( 'Reduced rate', 'woocommerce' ), 'label' => __( 'Reduced rate', 'woocommerce' ),
'value' => 'reduced-rate', 'value' => 'reduced-rate',
], ),
[ array(
'label' => __( 'Zero rate', 'woocommerce' ), 'label' => __( 'Zero rate', 'woocommerce' ),
'value' => 'zero-rate', 'value' => 'zero-rate',
], ),
], ),
], ),
] )
); );
} }
@ -339,24 +340,24 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
private function add_inventory_group_blocks() { private function add_inventory_group_blocks() {
$inventory_group = $this->get_group_by_id( $this::GROUP_IDS['INVENTORY'] ); $inventory_group = $this->get_group_by_id( $this::GROUP_IDS['INVENTORY'] );
$inventory_group->add_block( $inventory_group->add_block(
[ array(
'id' => 'inventory-single-variation-notice', 'id' => 'inventory-single-variation-notice',
'blockName' => 'woocommerce/product-single-variation-notice', 'blockName' => 'woocommerce/product-single-variation-notice',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'content' => __( '<strong>Youre editing details specific to this variation.</strong> Some information, like description and images, will be inherited from the main product, <noticeLink><parentProductName/></noticeLink>.', 'woocommerce' ), 'content' => __( '<strong>Youre editing details specific to this variation.</strong> Some information, like description and images, will be inherited from the main product, <noticeLink><parentProductName/></noticeLink>.', 'woocommerce' ),
'type' => 'info', 'type' => 'info',
'isDismissible' => true, 'isDismissible' => true,
'name' => $this::SINGLE_VARIATION_NOTICE_DISMISSED_OPTION, 'name' => $this::SINGLE_VARIATION_NOTICE_DISMISSED_OPTION,
], ),
] )
); );
// Product Inventory Section. // Product Inventory Section.
$product_inventory_section = $inventory_group->add_section( $product_inventory_section = $inventory_group->add_section(
[ array(
'id' => 'product-variation-inventory-section', 'id' => 'product-variation-inventory-section',
'order' => 20, 'order' => 20,
'attributes' => [ 'attributes' => array(
'title' => __( 'Inventory', 'woocommerce' ), 'title' => __( 'Inventory', 'woocommerce' ),
'description' => sprintf( 'description' => sprintf(
/* translators: %1$s: Inventory settings link opening tag. %2$s: Inventory settings link closing tag.*/ /* translators: %1$s: Inventory settings link opening tag. %2$s: Inventory settings link closing tag.*/
@ -365,28 +366,28 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
'</a>' '</a>'
), ),
'blockGap' => 'unit-40', 'blockGap' => 'unit-40',
], ),
] )
); );
$product_inventory_inner_section = $product_inventory_section->add_section( $product_inventory_inner_section = $product_inventory_section->add_section(
[ array(
'id' => 'product-variation-inventory-inner-section', 'id' => 'product-variation-inventory-inner-section',
'order' => 10, 'order' => 10,
] )
); );
$product_inventory_inner_section->add_block( $product_inventory_inner_section->add_block(
[ array(
'id' => 'product-variation-sku-field', 'id' => 'product-variation-sku-field',
'blockName' => 'woocommerce/product-sku-field', 'blockName' => 'woocommerce/product-sku-field',
'order' => 10, 'order' => 10,
] )
); );
$product_inventory_inner_section->add_block( $product_inventory_inner_section->add_block(
[ array(
'id' => 'product-variation-track-stock', 'id' => 'product-variation-track-stock',
'blockName' => 'woocommerce/product-toggle-field', 'blockName' => 'woocommerce/product-toggle-field',
'order' => 20, 'order' => 20,
'attributes' => [ 'attributes' => array(
'label' => __( 'Track stock quantity for this product', 'woocommerce' ), 'label' => __( 'Track stock quantity for this product', 'woocommerce' ),
'property' => 'manage_stock', 'property' => 'manage_stock',
'disabled' => 'yes' !== get_option( 'woocommerce_manage_stock' ), 'disabled' => 'yes' !== get_option( 'woocommerce_manage_stock' ),
@ -396,64 +397,64 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products&section=inventory' ) . '" target="_blank" rel="noreferrer">', '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products&section=inventory' ) . '" target="_blank" rel="noreferrer">',
'</a>' '</a>'
), ),
], ),
] )
); );
$product_inventory_quantity_conditional = $product_inventory_inner_section->add_block( $product_inventory_quantity_conditional = $product_inventory_inner_section->add_block(
[ array(
'id' => 'product-variation-inventory-quantity-conditional-wrapper', 'id' => 'product-variation-inventory-quantity-conditional-wrapper',
'blockName' => 'woocommerce/conditional', 'blockName' => 'woocommerce/conditional',
'order' => 30, 'order' => 30,
'attributes' => [ 'attributes' => array(
'mustMatch' => [ 'mustMatch' => array(
'manage_stock' => [ true ], 'manage_stock' => array( true ),
], ),
], ),
] )
); );
$product_inventory_quantity_conditional->add_block( $product_inventory_quantity_conditional->add_block(
[ array(
'id' => 'product-variation-inventory-quantity', 'id' => 'product-variation-inventory-quantity',
'blockName' => 'woocommerce/product-inventory-quantity-field', 'blockName' => 'woocommerce/product-inventory-quantity-field',
'order' => 10, 'order' => 10,
] )
); );
$product_stock_status_conditional = $product_inventory_section->add_block( $product_stock_status_conditional = $product_inventory_section->add_block(
[ array(
'id' => 'product-variation-stock-status-conditional-wrapper', 'id' => 'product-variation-stock-status-conditional-wrapper',
'blockName' => 'woocommerce/conditional', 'blockName' => 'woocommerce/conditional',
'order' => 20, 'order' => 20,
'attributes' => [ 'attributes' => array(
'mustMatch' => [ 'mustMatch' => array(
'manage_stock' => [ false ], 'manage_stock' => array( false ),
], ),
], ),
] )
); );
$product_stock_status_conditional->add_block( $product_stock_status_conditional->add_block(
[ array(
'id' => 'product-variation-stock-status', 'id' => 'product-variation-stock-status',
'blockName' => 'woocommerce/product-radio-field', 'blockName' => 'woocommerce/product-radio-field',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'title' => __( 'Stock status', 'woocommerce' ), 'title' => __( 'Stock status', 'woocommerce' ),
'property' => 'stock_status', 'property' => 'stock_status',
'options' => [ 'options' => array(
[ array(
'label' => __( 'In stock', 'woocommerce' ), 'label' => __( 'In stock', 'woocommerce' ),
'value' => 'instock', 'value' => 'instock',
], ),
[ array(
'label' => __( 'Out of stock', 'woocommerce' ), 'label' => __( 'Out of stock', 'woocommerce' ),
'value' => 'outofstock', 'value' => 'outofstock',
], ),
[ array(
'label' => __( 'On backorder', 'woocommerce' ), 'label' => __( 'On backorder', 'woocommerce' ),
'value' => 'onbackorder', 'value' => 'onbackorder',
], ),
], ),
], ),
] )
); );
} }
@ -463,43 +464,43 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
private function add_shipping_group_blocks() { private function add_shipping_group_blocks() {
$shipping_group = $this->get_group_by_id( $this::GROUP_IDS['SHIPPING'] ); $shipping_group = $this->get_group_by_id( $this::GROUP_IDS['SHIPPING'] );
$shipping_group->add_block( $shipping_group->add_block(
[ array(
'id' => 'shipping-single-variation-notice', 'id' => 'shipping-single-variation-notice',
'blockName' => 'woocommerce/product-single-variation-notice', 'blockName' => 'woocommerce/product-single-variation-notice',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'content' => __( '<strong>Youre editing details specific to this variation.</strong> Some information, like description and images, will be inherited from the main product, <noticeLink><parentProductName/></noticeLink>.', 'woocommerce' ), 'content' => __( '<strong>Youre editing details specific to this variation.</strong> Some information, like description and images, will be inherited from the main product, <noticeLink><parentProductName/></noticeLink>.', 'woocommerce' ),
'type' => 'info', 'type' => 'info',
'isDismissible' => true, 'isDismissible' => true,
'name' => $this::SINGLE_VARIATION_NOTICE_DISMISSED_OPTION, 'name' => $this::SINGLE_VARIATION_NOTICE_DISMISSED_OPTION,
], ),
] )
); );
// Virtual section. // Virtual section.
$shipping_group->add_section( $shipping_group->add_section(
[ array(
'id' => 'product-variation-virtual-section', 'id' => 'product-variation-virtual-section',
'order' => 20, 'order' => 20,
] )
)->add_block( )->add_block(
[ array(
'id' => 'product-variation-virtual', 'id' => 'product-variation-virtual',
'blockName' => 'woocommerce/product-toggle-field', 'blockName' => 'woocommerce/product-toggle-field',
'order' => 10, 'order' => 10,
'attributes' => [ 'attributes' => array(
'property' => 'virtual', 'property' => 'virtual',
'checkedValue' => false, 'checkedValue' => false,
'uncheckedValue' => true, 'uncheckedValue' => true,
'label' => __( 'This variation requires shipping or pickup', 'woocommerce' ), 'label' => __( 'This variation requires shipping or pickup', 'woocommerce' ),
], ),
] )
); );
// Product Shipping Section. // Product Shipping Section.
$product_fee_and_dimensions_section = $shipping_group->add_section( $product_fee_and_dimensions_section = $shipping_group->add_section(
[ array(
'id' => 'product-variation-fee-and-dimensions-section', 'id' => 'product-variation-fee-and-dimensions-section',
'order' => 30, 'order' => 30,
'attributes' => [ 'attributes' => array(
'title' => __( 'Fees & dimensions', 'woocommerce' ), 'title' => __( 'Fees & dimensions', 'woocommerce' ),
'description' => sprintf( 'description' => sprintf(
/* translators: %1$s: How to get started? link opening tag. %2$s: How to get started? link closing tag.*/ /* translators: %1$s: How to get started? link opening tag. %2$s: How to get started? link closing tag.*/
@ -507,22 +508,22 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
'<a href="https://woocommerce.com/posts/how-to-calculate-shipping-costs-for-your-woocommerce-store/" target="_blank" rel="noreferrer">', '<a href="https://woocommerce.com/posts/how-to-calculate-shipping-costs-for-your-woocommerce-store/" target="_blank" rel="noreferrer">',
'</a>' '</a>'
), ),
], ),
] )
); );
$product_fee_and_dimensions_section->add_block( $product_fee_and_dimensions_section->add_block(
[ array(
'id' => 'product-variation-shipping-class', 'id' => 'product-variation-shipping-class',
'blockName' => 'woocommerce/product-shipping-class-field', 'blockName' => 'woocommerce/product-shipping-class-field',
'order' => 10, 'order' => 10,
] )
); );
$product_fee_and_dimensions_section->add_block( $product_fee_and_dimensions_section->add_block(
[ array(
'id' => 'product-variation-shipping-dimensions', 'id' => 'product-variation-shipping-dimensions',
'blockName' => 'woocommerce/product-shipping-dimensions-fields', 'blockName' => 'woocommerce/product-shipping-dimensions-fields',
'order' => 20, 'order' => 20,
] )
); );
} }
} }

View File

@ -3,16 +3,17 @@
* WooCommerce Section Block class. * WooCommerce Section Block class.
*/ */
namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates; namespace Automattic\WooCommerce\Internal\Admin\Features\ProductBlockEditor\ProductTemplates;
use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface; use Automattic\WooCommerce\Admin\BlockTemplates\BlockTemplateInterface;
use Automattic\WooCommerce\Admin\BlockTemplates\ContainerInterface; use Automattic\WooCommerce\Admin\BlockTemplates\ContainerInterface;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\SectionInterface;
/** /**
* Class for Section block. * Class for Section block.
*/ */
class Section extends ProductBlock implements SectionInterface { class Section extends ProductBlock implements SectionInterface {
// phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
/** /**
* Section Block constructor. * Section Block constructor.
* *
@ -30,6 +31,7 @@ class Section extends ProductBlock implements SectionInterface {
} }
parent::__construct( array_merge( array( 'blockName' => 'woocommerce/product-section' ), $config ), $root_template, $parent ); parent::__construct( array_merge( array( 'blockName' => 'woocommerce/product-section' ), $config ), $root_template, $parent );
} }
// phpcs:enable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
/** /**
* Add a section block type to this template. * Add a section block type to this template.

View File

@ -2,7 +2,7 @@
namespace Automattic\WooCommerce\Tests\Admin\ProductBlockEditor\ProductTemplates; namespace Automattic\WooCommerce\Tests\Admin\ProductBlockEditor\ProductTemplates;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\AbstractProductFormTemplate; use Automattic\WooCommerce\Internal\Admin\Features\ProductBlockEditor\ProductTemplates\AbstractProductFormTemplate;
use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductFormTemplateInterface; use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplates\ProductFormTemplateInterface;
class CustomProductFormTemplate extends AbstractProductFormTemplate implements ProductFormTemplateInterface { class CustomProductFormTemplate extends AbstractProductFormTemplate implements ProductFormTemplateInterface {