Score:0

How to get Commerce price without any adjustments

in flag

I'm trying to show "Buy for XX USD more and get free shipping", I know how to get $cart->get('total_price')->getValue()[0]['number'] but it is including any adjustments including shipment, I need just price of all items in a cart without any adjustments.

Using devel I found out that shipment value is stored in $cart->get('adjustments')->getValue()[0]['value'], but I don't know how to get to protected amount->number (see picture), any help? ) MY variable $PriceWithoutAdjustments = $cart->get('adjustments')->getValue()[0]['value'];)

Or even better, how to get price without adjustments?

Many thanksDSM

john Smith avatar
gr flag
try `$priceWithoutAdjustments->getAmount()`
Zdeněk Nováček avatar
in flag
@johnSmith, thanks!, almost there.. just need to get number value, `$PriceWithoutAdjustments->getAmount()['number']` is not working
Score:0
gr flag

You cannot work with those classes like with drupal´s fieldable entities

There is this nice little hint in your debug output that shows which class is used e.g

Drupal\commerce_order\Adjustment

So i dont know commerce plugin but i can look into the source, i just searched for the classes in the online available source-code

and see that Adjustment has the method getAmount

$priceWithoutAdjustments->getAmount();

which will return of type Drupal\commerce_price\Price

which has a method ->getNumber()

which seems to be what you are looking for :)

Zdeněk Nováček avatar
in flag
Thanks! That's it! Finally I understood.. Many thanks.
john Smith avatar
gr flag
Youre welcome, please mark this as answer then
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.