0

Following code I'm using for low stock mail for store wise in daily.

    $collection = $this->lowStockFactory->create()
            ->joinAttribute('name', 'catalog_product/name', 'entity_id', null, 'inner')
            ->joinTable(
                'catalog_product_website',
                'product_id = entity_id',
                ['product_id', 'website_id']
            )->filterByIsQtyProductTypes()->joinInventoryItem(
                ['qty']
            #)->useManageStockFilter()->useNotifyStockQtyFilter();
        )->useManageStockFilter()->useNotifyStockQtyFilter()->addAttributeToFilter('status',
                \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);     

       return $this->products;

But cron scheduling and command run collection filtering in a different manner. when using cron scheduling enable product filter by using all store view, but command filtering enables product in-store wise. anyone have idea why same method working different behavior.

Excution SQL Queries as below

Cron

SELECT `e`.*, `at_name`.`value` AS `name`, `catalog_product_website`.`product_id`, `catalog_product_website`.`website_id`, `lowstock_inventory_item`.`qty`, `at_status`.`value` AS `status` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_product_entity_varchar` AS `at_name` ON (`at_name`.`row_id` = `e`.`row_id`) AND (`at_name`.`attribute_id` = '70') AND (`at_name`.`store_id` = 0)
 INNER JOIN `catalog_product_website` ON (catalog_product_website.product_id =e.entity_id)
 INNER JOIN `cataloginventory_stock_item` AS `lowstock_inventory_item` ON e.entity_id = lowstock_inventory_item.product_id
 INNER JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`row_id` = `e`.`row_id`) AND (`at_status`.`attribute_id` = '94') AND (`at_status`.`store_id` = 0) WHERE ((((`e`.`type_id` = 'simple') OR (`e`.`type_id` = 'virtual') OR (`e`.`type_id` = 'downloadable') OR (`e`.`type_id` = 'giftcard'))) AND (IF(lowstock_inventory_item.use_config_manage_stock = 1, 1, lowstock_inventory_item.manage_stock) = 1) AND (lowstock_inventory_item.qty < IF(lowstock_inventory_item.use_config_notify_stock_qty = 1, 10, lowstock_inventory_item.notify_stock_qty)) AND (at_status.value = '1')) AND (e.created_in <= '1603646940') AND (e.updated_in > '1603646940')

Command

SELECT `e`.*, IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`, `catalog_product_website`.`product_id`, `catalog_product_website`.`website_id`, `lowstock_inventory_item`.`qty`, IF(at_status.value_id > 0, at_status.value, at_status_default.value) AS `status` FROM 
`catalog_product_entity` AS `e`
 INNER JOIN `catalog_product_entity_varchar` AS `at_name_default` ON (`at_name_default`.`row_id` = `e`.`row_id`) AND (`at_name_default`.`attribute_id` = '70') AND `at_name_default`.`store_id` = 0
 LEFT JOIN `catalog_product_entity_varchar` AS `at_name` ON (`at_name`.`row_id` = `e`.`row_id`) AND (`at_name`.`attribute_id` = '70') AND (`at_name`.`store_id` = 1)
 INNER JOIN `catalog_product_website` ON (catalog_product_website.product_id =e.entity_id)
 INNER JOIN `cataloginventory_stock_item` AS `lowstock_inventory_item` ON e.entity_id = lowstock_inventory_item.product_id
 INNER JOIN `catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`row_id` = `e`.`row_id`) AND (`at_status_default`.`attribute_id` = '94') AND `at_status_default`.`store_id` = 0
 LEFT JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`row_id` = `e`.`row_id`) AND (`at_status`.`attribute_id` = '94') AND (`at_status`.`store_id` = 1) WHERE ((((`e`.`type_id` = 'simple') OR (`e`.`type_id` = 'virtual') OR (`e`.`type_id` = 'downloadable') OR (`e`.`type_id` = 'giftcard'))) AND (IF(lowstock_inventory_item.use_config_manage_stock = 1, 1, lowstock_inventory_item.manage_stock) = 1) AND (lowstock_inventory_item.qty < IF(lowstock_inventory_item.use_config_notify_stock_qty = 1, 10, lowstock_inventory_item.notify_stock_qty)) AND (IF(at_status.value_id > 0, at_status.value, at_status_default.value) = '1')) AND (e.created_in <= '1603646940') AND (e.updated_in > '1603646940')
2
  • 2
    How cron is running? Via magento crontab.xml or command is running via system crontab? Is flow to the potined code the same ? Are area the same ? – Konrad Siamro Feb 17 at 10:31
  • @KonradSiamro 'crontab' set the area code when the process runs via console command. Not specified the area code when running the crontab.xml – Singhe Feb 18 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.