array( 'shirts' ), 'productId' => '10' ); $variants = array( array( 'variant_id' => '11', 'size_label' => 'M', 'available' => true ), array( 'variant_id' => '12', 'size_label' => 'L', 'available' => true ), ); $base = array( 'active' => true, 'withinQuota' => true, 'size' => array( 'hasSizeGuide' => true, 'targeting' => array( 'mode' => 'all', 'categories' => array(), 'productIds' => array() ), 'guides' => array( array( 'id' => 'g', 'categories' => array( 'categories' => array() ), 'labels' => array( 'M', 'L' ) ) ), ), ); echo "Storefront size entry\n"; size_check( 'two distinct available sizes render', true, Storefront::size_is_eligible( $base, $context, $variants ) ); size_check( 'shop default resolution is reported', 'shop_default', Storefront::size_guide_resolution( $base, $context ) ); $tryon_spent = $base; $tryon_spent['withinQuota'] = false; size_check( 'try-on quota does not hide the independent size entry', true, Storefront::size_is_eligible( $tryon_spent, $context, $variants ) ); $missing_guide = $base; $missing_guide['size']['hasSizeGuide'] = false; size_check( 'missing guide is hidden', false, Storefront::size_is_eligible( $missing_guide, $context, $variants ) ); $wrong_labels = $base; $wrong_labels['size']['guides'][0]['labels'] = array( 'XS' ); size_check( 'guide without a real variation match is hidden', false, Storefront::size_is_eligible( $wrong_labels, $context, $variants ) ); $sold_out = array( array( 'variant_id' => '11', 'size_label' => 'M', 'available' => true ), array( 'variant_id' => '12', 'size_label' => 'L', 'available' => false ), ); size_check( 'one available size with another sold out is hidden', false, Storefront::size_is_eligible( $base, $context, $sold_out ) ); size_check( 'duplicate size labels across colors count once', false, Storefront::size_is_eligible( $base, $context, array( array( 'variant_id' => '11', 'size_label' => 'M', 'available' => true ), array( 'variant_id' => '12', 'size_label' => ' m ', 'available' => true ), ) ) ); foreach ( array( 'One Size', 'OS', 'Taglia Unica', 'Talla Única' ) as $one_size ) { $one_size_status = $base; $one_size_status['size']['guides'][0]['labels'] = array( $one_size, 'M' ); size_check( "{$one_size} is hidden", false, Storefront::size_is_eligible( $one_size_status, $context, array( array( 'variant_id' => '11', 'size_label' => $one_size, 'available' => true ), array( 'variant_id' => '12', 'size_label' => 'M', 'available' => true ), ) ) ); } $legacy = $base; unset( $legacy['size']['guides'] ); size_check( 'legacy payload without guides fails closed', false, Storefront::size_is_eligible( $legacy, $context, $variants ) ); $excluded = $base; $excluded['size']['targeting'] = array( 'mode' => 'exclude', 'categories' => array( 'shirts' ), 'productIds' => array() ); size_check( 'size targeting is independent and enforced', false, Storefront::size_is_eligible( $excluded, $context, $variants ) ); $collection = $base; $collection['size']['guides'][0]['categories']['categories'] = array( 'shirts' ); size_check( 'collection resolution is reported', 'collection', Storefront::size_guide_resolution( $collection, $context ) ); $explicit = $base; $explicit['size']['guides'] = array( array( 'id' => 'category', 'categories' => array( 'categories' => array( 'shirts' ) ), 'labels' => array( 'XS', 'S' ) ), array( 'id' => 'product', 'categories' => array( 'categories' => array(), 'productIds' => array( '42', '43' ) ), 'labels' => array( 'M', 'L' ) ), ); $chosen = array( 'productId' => '42', 'categories' => array( 'shirts' ) ); size_check( 'product takes priority over category', true, Storefront::size_is_eligible( $explicit, $chosen, $variants ) ); size_check( 'product analytics enum', 'product_id', Storefront::size_guide_resolution( $explicit, $chosen ) ); size_check( 'neighbor does not receive product guide', false, Storefront::size_is_eligible( $explicit, array( 'productId' => '44', 'categories' => array( 'shirts' ) ), $variants ) ); size_check( 'explicit still rejects one size', false, Storefront::size_is_eligible( $explicit, $chosen, array( array( 'size_label' => 'One Size', 'available' => true ) ) ) ); $explicit['size']['guides'] = array( $explicit['size']['guides'][1] ); size_check( 'product-only guide is never fallback', false, Storefront::size_is_eligible( $explicit, array( 'productId' => '99', 'categories' => array() ), $variants ) ); echo "\n{$passed} passed, {$failed} failed\n"; exit( $failed > 0 ? 1 : 0 );