41, 'crosssells' => 42, 'upsells' => 43, 'related' => 44, 'semantic_related' => 45, ); const EFFECTIVE_LIMIT = 8; const SAME_NEEDS_LIMIT = 6; public static function in_layer() { return class_exists( 'Rooster\Core\Defer' ) && method_exists( 'Rooster\Core\Defer', 'is_full' ) && \Rooster\Core\Defer::is_full(); } public static function serves( $surface ) { return in_array( (string) $surface, self::SURFACES, true ) && self::in_layer() && ! ( class_exists( 'AIEO_Reco_Experiment' ) && AIEO_Reco_Experiment::is_running() ); } public static function ids( $surface, $product_id ) { $product_id = (int) $product_id; if ( $product_id <= 0 || ! function_exists( 'wc_get_product' ) ) { return array(); } if ( class_exists( 'AIEO_DMM_Product_Display' ) && ! AIEO_DMM_Product_Display::reco_surface_visible( (string) $surface ) ) { return array(); } switch ( (string) $surface ) { case 'upsells': return self::surfacable( self::collected( $product_id, 'upsells', '_upsell_ids' ), $product_id ); case 'crosssells': return self::surfacable( self::collected( $product_id, 'crosssells', '_crosssell_ids' ), $product_id ); case 'related': $ids = self::surfacable( self::collected( $product_id, 'related', null ), $product_id ); shuffle( $ids ); return $ids; case 'same_needs': if ( ! class_exists( 'AI_eShop_Need_Suggestions' ) && file_exists( __DIR__ . '/class-need-suggestions.php' ) ) { require_once __DIR__ . '/class-need-suggestions.php'; } if ( ! class_exists( 'AI_eShop_Need_Suggestions' ) ) { return array(); } $same = AI_eShop_Need_Suggestions::get_instance()->get_suggestions( $product_id ); return array_slice( self::surfacable( is_array( $same ) ? $same : array(), $product_id ), 0, self::SAME_NEEDS_LIMIT ); case 'semantic_related': if ( ! class_exists( 'AIEO_Semantic_Reco_Source' ) ) { return array(); } $limit = class_exists( 'AIEO_DMM_Settings' ) ? (int) AIEO_DMM_Settings::get( 'semantic.related_block_limit', 6 ) : 6; $limit = max( 1, min( 24, $limit ) ); $ids = (array) apply_filters( 'aieo_semantic_reco_ids', (array) AIEO_Semantic_Reco_Source::ids_for( $product_id, $limit * 2 ), $product_id, $limit ); return array_slice( self::surfacable( array_values( array_filter( array_map( 'intval', $ids ) ) ), $product_id ), 0, $limit ); } return array(); } public static function html( $surface, array $ids ) { $surface = (string) $surface; $ids = array_values( array_unique( array_filter( array_map( 'intval', $ids ) ) ) ); if ( array() === $ids || ! isset( self::QUERY_IDS[ $surface ] ) || ! function_exists( 'render_block' ) ) { return ''; } $titles = is_callable( array( 'aieo_display_recommendations', 'section_titles' ) ) ? (array) aieo_display_recommendations::section_titles() : array(); $title = isset( $titles[ $surface ] ) ? (string) $titles[ $surface ] : ''; $collection = array( 'queryId' => self::QUERY_IDS[ $surface ], 'query' => array( 'perPage' => count( $ids ), 'pages' => 1, 'offset' => 0, 'postType' => 'product', 'order' => 'asc', 'orderBy' => 'post__in', 'search' => '', 'exclude' => array(), 'inherit' => false, 'taxQuery' => array(), 'isProductCollectionBlock' => true, 'featured' => false, 'woocommerceOnSale' => false, 'woocommerceStockStatus' => array( 'instock', 'onbackorder' ), 'woocommerceAttributes' => array(), 'woocommerceHandPickedProducts' => $ids, 'filterable' => false, ), 'tagName' => 'div', 'displayLayout' => array( 'type' => 'flex', 'columns' => 4, 'shrinkColumns' => true ), 'dimensions' => array( 'widthType' => 'fill' ), 'collection' => 'woocommerce/product-collection/hand-picked', 'hideControls' => array( 'inherit', 'filterable' ), 'queryContextIncludes' => array( 'collection' ), 'align' => 'wide', 'className' => 'is-style-rooster-slider', ); $head = '' === $title ? '' : '' . '