在Magento工作,我目前正在尝试修改销售确认电子邮件中显示的产品表,这样,如果客户下订单时产品缺货,则会显示产品提前期(如果产品有库存,显示库存消息。
我遇到了一个问题,从我看到的数量变量应该是-1,但实际上是0:
$stock = Mage::getModel('cataloginventory/stock_item')->load(Mage::getModel("catalog/product")->getIdBySku($this->getSku($_item)));
echo $stock->getQty();
if($stock->getQty() >= 0){
echo 'in stock message';
}
else {
echo 'out of stock message';
} ?>
cataloginventory_stock_item表中的Qty字段是-1.0000,但是echo $ stock-> getQty();打印0.0000(与$ stock的var_dump一样)。
我想我正在把getQty()从正确的位置/相应的表调用到我在phpMyAdmin中查看的那个...
var_dump($ stock)返回以下内容:
object(Mage_CatalogInventory_Model_Stock_Item)#861 (20) { ["_minSaleQtyCache":"Mage_CatalogInventory_Model_Stock_Item":private]=> array(0) { } ["_qtyIncrements":protected]=> NULL ["_eventPrefix":protected]=> string(27) "cataloginventory_stock_item" ["_eventObject":protected]=> string(4) "item" ["_productInstance":protected]=> NULL ["_customerGroupId":protected]=> NULL ["_processIndexEvents":protected]=> bool(true) ["_resourceName":protected]=> string(27) "cataloginventory/stock_item" ["_resource":protected]=> NULL ["_resourceCollectionName":protected]=> string(38) "cataloginventory/stock_item_collection" ["_cacheTag":protected]=> bool(false) ["_dataSaveAllowed":protected]=> bool(true) ["_isObjectNew":protected]=> NULL ["_data":protected]=> array(28) { ["item_id"]=> string(5) "13931" ["product_id"]=> string(5) "14032" ["stock_id"]=> string(1) "1" ["qty"]=> string(6) "0.0000" ["min_qty"]=> string(6) "0.0000" ["use_config_min_qty"]=> string(1) "1" ["is_qty_decimal"]=> string(1) "0" ["backorders"]=> string(1) "1" ["use_config_backorders"]=> string(1) "0" ["min_sale_qty"]=> string(6) "1.0000" ["use_config_min_sale_qty"]=> string(1) "1" ["max_sale_qty"]=> string(6) "0.0000" ["use_config_max_sale_qty"]=> string(1) "1" ["is_in_stock"]=> string(1) "1" ["low_stock_date"]=> string(19) "2016-08-15 10:38:30" ["notify_stock_qty"]=> NULL ["use_config_notify_stock_qty"]=> string(1) "1" ["manage_stock"]=> string(1) "1" ["use_config_manage_stock"]=> string(1) "0" ["stock_status_changed_auto"]=> string(1) "0" ["use_config_qty_increments"]=> string(1) "1" ["qty_increments"]=> string(6) "0.0000" ["use_config_enable_qty_inc"]=> string(1) "1" ["enable_qty_increments"]=> string(1) "0" ["is_decimal_divided"]=> string(1) "0" ["type_id"]=> string(6) "simple" ["stock_status_changed_automatically"]=> string(1) "0" ["use_config_enable_qty_increments"]=> string(1) "1" } ["_hasDataChanges":protected]=> bool(false) ["_origData":protected]=> array(28) { ["item_id"]=> string(5) "13931" ["product_id"]=> string(5) "14032" ["stock_id"]=> string(1) "1" ["qty"]=> string(6) "0.0000" ["min_qty"]=> string(6) "0.0000" ["use_config_min_qty"]=> string(1) "1" ["is_qty_decimal"]=> string(1) "0" ["backorders"]=> string(1) "1" ["use_config_backorders"]=> string(1) "0" ["min_sale_qty"]=> string(6) "1.0000" ["use_config_min_sale_qty"]=> string(1) "1" ["max_sale_qty"]=> string(6) "0.0000" ["use_config_max_sale_qty"]=> string(1) "1" ["is_in_stock"]=> string(1) "1" ["low_stock_date"]=> string(19) "2016-08-15 10:38:30" ["notify_stock_qty"]=> NULL ["use_config_notify_stock_qty"]=> string(1) "1" ["manage_stock"]=> string(1) "1" ["use_config_manage_stock"]=> string(1) "0" ["stock_status_changed_auto"]=> string(1) "0" ["use_config_qty_increments"]=> string(1) "1" ["qty_increments"]=> string(6) "0.0000" ["use_config_enable_qty_inc"]=> string(1) "1" ["enable_qty_increments"]=> string(1) "0" ["is_decimal_divided"]=> string(1) "0" ["type_id"]=> string(6) "simple" ["stock_status_changed_automatically"]=> string(1) "0" ["use_config_enable_qty_increments"]=> string(1) "1" } ["_idFieldName":protected]=> NULL ["_isDeleted":protected]=> bool(false) ["_oldFieldsMap":protected]=> array(2) { ["stock_status_changed_automatically"]=> string(25) "stock_status_changed_auto" ["use_config_enable_qty_increments"]=> string(25) "use_config_enable_qty_inc" } ["_syncFieldsMap":protected]=> array(4) { ["stock_status_changed_automatically"]=> string(25) "stock_status_changed_auto" ["use_config_enable_qty_increments"]=> string(25) "use_config_enable_qty_inc" ["stock_status_changed_auto"]=> string(34) "stock_status_changed_automatically" ["use_config_enable_qty_inc"]=> string(32) "use_config_enable_qty_increments" } }