I have a custom table for specific product type to store the product qty, the query to select the qty is like this for example:
SELECT a.qty FROM custom_product_table WHERE product_id = 1;
i noticed the qty column is rendered in this file
vendor/magento/module-catalog-inventory/Ui/DataProvider/Product/AddQuantityFieldToCollection.php
public function addField(Collection $collection, $field, $alias = null)
{
$collection->joinField(
'qty',
'cataloginventory_stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
);
}
How can i assign my custom query as qty column only when the product type id is my custom product type id, for example type_id = 5
?
IF(e.type_id = 4)
(SELECT a.qty FROM custom_product_table WHERE product_id = e.entity_id) AS qty
ELSE
$collection->joinField(
'qty',
'cataloginventory_stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
) AS qty