Want to retrieve a product’s Magento 2 tier prices as an array and store them in a JavaScript variable for later use? Follow these steps:
|
1 2 3 4 5 6 7 |
<script> var tierPrices = <?= json_encode(array_map(fn($t) => [ 'qty' => (float)$t->getQty(), 'price' => (float)$t->getValue(), 'customer_group_id' => (int)$t->getCustomerGroupId() ], $product->getTierPrices())) ?>; </script> |
You can now access the values from JavaScript, for example using a function that…