Automattic\WooCommerce\Internal\ProductFeed\Integrations\POSCatalog
ProductMapper::map_product
Map WooCommerce product to catalog row
Метод класса: ProductMapper{}
Хуки из метода
Возвращает
Массив. Mapped product data array.
Использование
$ProductMapper = new ProductMapper(); $ProductMapper->map_product( $product ): array;
- $product(WC_Product) (обязательный)
- Product to map.
Список изменений
| С версии 10.5.0 | Введена. |
Код ProductMapper::map_product() ProductMapper::map product WC 10.5.2
public function map_product( WC_Product $product ): array {
$is_variation = $product->is_type( 'variation' );
$controller = $is_variation
? $this->variations_controller
: $this->products_controller;
// This should never be the case, as the class should be loaded through DI.
if ( null === $controller ) {
throw new \RuntimeException( 'ProductMapper::init() must be called before map_product().' );
}
$request = $is_variation ? $this->get_variations_request() : $this->get_products_request();
$response = $controller->prepare_object_for_response( $product, $request );
// Apply _fields filtering (normally done by REST server dispatch).
$fields = $is_variation ? $this->variation_fields : $this->fields;
if ( null !== $fields ) {
$response = rest_filter_response_fields( $response, rest_get_server(), $request );
}
$row = array(
'type' => $product->get_type(),
'data' => $response->get_data(),
);
/**
* Filter mapped catalog product data.
*
* @since 10.5.0
* @param array $row Mapped product data.
* @param WC_Product $product Product object.
*/
return apply_filters( 'woocommerce_pos_catalog_map_product', $row, $product );
}