这是print_r($this->Product)
:
[stock_item] => Mage_CatalogInventory_Model_Stock_Item Object
(
[_minSaleQtyCache:Mage_CatalogInventory_Model_Stock_Item:private] => Array
(
)
[_qtyIncrements:protected] =>
[_eventPrefix:protected] => cataloginventory_stock_item
[_eventObject:protected] => item
[_productInstance:protected] => Mage_Catalog_Model_Product Object
*RECURSION*
[_customerGroupId:protected] =>
[_processIndexEvents:protected] => 1
[_resourceName:protected] => cataloginventory/stock_item
[_resource:protected] =>
[_resourceCollectionName:protected] => cataloginventory/stock_item_collection
[_cacheTag:protected] =>
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[item_id] => 3843
[product_id] => 2573
[stock_id] => 1
[qty] => 2
[min_qty] => 0.0000
[use_config_min_qty] => 1
[is_qty_decimal] => 0
[backorders] => 0
[use_config_backorders] => 1
[min_sale_qty] => 1.0000
[use_config_min_sale_qty] => 1
[max_sale_qty] => 0.0000
[use_config_max_sale_qty] => 1
[is_in_stock] => 1
[low_stock_date] =>
[notify_stock_qty] =>
[use_config_notify_stock_qty] => 1
[manage_stock] => 0
[use_config_manage_stock] => 1
[stock_status_changed_auto] => 0
[use_config_qty_increments] => 1
[qty_increments] => 0.0000
[use_config_enable_qty_inc] => 1
[enable_qty_increments] => 0
[is_decimal_divided] => 0
[type_id] => grouped
[stock_status_changed_automatically] => 0
[use_config_enable_qty_increments] => 1
[product_name] => Amino 12500
[store_id] => 1
[product_type_id] => grouped
[product_status_changed] => 1
[product_changed_websites] =>
)
[_hasDataChanges:protected] => 1
[_origData:protected] => Array
(
[item_id] => 3843
[product_id] => 2573
[stock_id] => 1
[qty] => 0.0000
[min_qty] => 0.0000
[use_config_min_qty] => 1
[is_qty_decimal] => 0
[backorders] => 0
[use_config_backorders] => 1
[min_sale_qty] => 1.0000
[use_config_min_sale_qty] => 1
[max_sale_qty] => 0.0000
[use_config_max_sale_qty] => 1
[is_in_stock] => 1
[low_stock_date] =>
[notify_stock_qty] =>
[use_config_notify_stock_qty] => 1
[manage_stock] => 0
[use_config_manage_stock] => 1
[stock_status_changed_auto] => 0
[use_config_qty_increments] => 1
[qty_increments] => 0.0000
[use_config_enable_qty_inc] => 1
[enable_qty_increments] => 0
[is_decimal_divided] => 0
[type_id] => grouped
[stock_status_changed_automatically] => 0
[use_config_enable_qty_increments] => 1
)
[_idFieldName:protected] => item_id
[_isDeleted:protected] =>
[_oldFiel
dsMap:protected] => Array
(
[stock_status_changed_automatically] => stock_status_changed_auto
[use_config_enable_qty_increments] => use_config_enable_qty_inc
)
[_syncFieldsMap:protected] => Array
(
[stock_status_changed_automatically] => stock_status_changed_auto
[use_config_enable_qty_increments] => use_config_enable_qty_inc
[stock_status_changed_auto] => stock_status_changed_automatically
[use_config_enable_qty_inc] => use_config_enable_qty_increments
)
)
正如您所看到的,有两个['qty']值。如果我输入:
$this->Product['stock_item']['qty'] = 2
;我可以访问第一个['qty']。我的问题是如何访问第二个['数量']? THX
答案 0 :(得分:2)
Magento为任何事物提供了魔法的吸气剂和制定者"数据",所以你可以这样做来获取和设置数量':
$qty = $this->product->getQty();
$this->product->setQty($qty);
但您也可以使用这些方法来获取数组:
$dataArray = $this->product->getData();
$origDataArray = $this->product->getOrigData();
$this->product->setData($dataArray);
$this->product->setOrigData($origDataArray);
或者这是获取/设置特定值:
$dataQty = $product->getData('qty');
$origDataQty = $product->getOrigData('qty');
$product->setData('qty', $dataQty);
$product->setOrigData('qty', $origDataQty);