1

How to get amount value from the below code.

Magento\Framework\Pricing\Amount\Base Object
(
    [amount:protected] => 2520
    [baseAmount:protected] => 
    [totalAdjustmentAmount:protected] => 
    [adjustmentAmounts:protected] => Array
        (
        )

    [adjustments:protected] => Array
        (
        )

)

I have try below but no luck

//print_r($amount->amount); exit;
6
  • try echo $yourobject->getAmount(); Jul 12, 2017 at 11:29
  • not work return empty
    – Ajay Patel
    Jul 12, 2017 at 11:35
  • same result empty
    – Ajay Patel
    Jul 12, 2017 at 11:37
  • try echo $obj->getAmount()->getValue(); (or) echo $obj->getValue();
    – lavanya
    Jul 12, 2017 at 11:48
  • I have added the simplest one ! Dec 2, 2019 at 13:16

4 Answers 4

4

If $amount is this object, use:

$amount->getValue();

How to find out by yourself:

Look at the source code of Magento\Framework\Pricing\Amount\Base and search for $this->amount. If you find a method that returns the value, you're done.

And there it is:

/**
 * Return full amount value
 *
 * @param null|string|array $exclude
 * @return float
 */
public function getValue($exclude = null)
{
    if ($exclude === null) {
        return $this->amount;
    } else {
        ...
    }
}
0
0

Try this :

echo '<pre>'; print_r($yourobject->getData());

and check what you are getting.

Or you can try like

echo '<pre>'; print_r(get_class_methods($yourobject));

It will give you all available methods available in this object, and you can try any of that method.

0

ok you can do below hack that is always work for me

convert your object into json

   $json = json_encode($object);

then convert your json to array

 $array = json_decode($json, true);
 print_r($array);   
0
Array
(
    [0] => Magento\Framework\Phrase Object
        (
            [text:Magento\Framework\Phrase:private] => "%fieldName" is required. Enter and try again.
            [arguments:Magento\Framework\Phrase:private] => Array
                (
                    [fieldName] => street
                )

        )

    [1] => Magento\Framework\Phrase Object
        (
            [text:Magento\Framework\Phrase:private] => "%fieldName" is required. Enter and try again.
            [arguments:Magento\Framework\Phrase:private] => Array
                (
                    [fieldName] => city
                )

        )

    [2] => Magento\Framework\Phrase Object
        (
            [text:Magento\Framework\Phrase:private] => "%fieldName" is required. Enter and try again.
            [arguments:Magento\Framework\Phrase:private] => Array
                (
                    [fieldName] => postcode
                )

        )

)

I was getting this and I got the value like this.

$errors[0]->getArguments()['fieldName']

Or

foreach ($errors as $error){
   $value = $error->getArguments()['fieldName'];
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.