Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow
WebflowMapper::extract_stock
Map Webflow inventory shape to WC stock fields.
Метод класса: WebflowMapper{}
Хуков нет.
Возвращает
array{manage_stock: bool, stock_quantity: ?int, stock_status: string}.
Использование
// private - только в коде основоного (родительского) класса $result = $this->extract_stock( $sku_field ): array;
- $sku_field(объект) (обязательный)
- SKU fieldData.
Код WebflowMapper::extract_stock() WebflowMapper::extract stock WC 11.2.2
private function extract_stock( object $sku_field ): array {
$inventory = isset( $sku_field->inventory ) && is_object( $sku_field->inventory ) ? $sku_field->inventory : null;
if ( null === $inventory ) {
return array(
'manage_stock' => false,
'stock_quantity' => null,
'stock_status' => 'instock',
);
}
$type = isset( $inventory->type ) ? (string) $inventory->type : 'infinite';
if ( 'finite' !== $type ) {
return array(
'manage_stock' => false,
'stock_quantity' => null,
'stock_status' => 'instock',
);
}
$quantity = isset( $inventory->quantity ) ? (int) $inventory->quantity : 0;
return array(
'manage_stock' => true,
'stock_quantity' => $quantity,
'stock_status' => $quantity > 0 ? 'instock' : 'outofstock',
);
}