Attila Naghi
Attila Naghi

Reputation: 2686

how do I access array values in php Magento?

hi this is the part of result of 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
            )
    )

As you can see there is 2 ['qty'] values . If I type :

$this->Product['stock_item']['qty'] = 2; I can access the first ['qty']. My question is how can i access the second ['qty'] ? Thx

Upvotes: 0

Views: 1417

Answers (1)

Christoffer Bubach
Christoffer Bubach

Reputation: 1686

Magento provides magic getters and setters for anything "data", so you could do this to get and set 'qty':

$qty = $this->product->getQty();
$this->product->setQty($qty);

But you can also use these methods to get the arrays:

$dataArray     = $this->product->getData();
$origDataArray = $this->product->getOrigData();

$this->product->setData($dataArray);
$this->product->setOrigData($origDataArray);

Or this to get/set a specific value:

$dataQty     = $product->getData('qty');
$origDataQty = $product->getOrigData('qty');

$product->setData('qty', $dataQty);
$product->setOrigData('qty', $origDataQty);

Upvotes: 2

Related Questions