0

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

6
  • They are from different properties ? data and origData Commented Apr 17, 2014 at 13:51
  • What do you mean by different properties ? Commented Apr 17, 2014 at 13:52
  • [_data:protected] => Array ( [qty] => 2 and [_origData:protected] => Array ( [qty] => 0.0000 seems to be hold by two different keys from your main key/object Commented Apr 17, 2014 at 13:53
  • ok, but how can i access it ? :D Commented Apr 17, 2014 at 13:59
  • @RoyalBg can you invite me on chat ? Commented Apr 17, 2014 at 14:02

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.