Question

As it stand I have managed to pull the Customer Group ID, Price Quantity and the Price itself. However there are other attributes:

  • Price ID
  • Website ID
  • All Groups
  • Percentage Value
  • Website Price

None of these I am able to access currently. Here is my current code snippet:

$product = $this->_productRepository->get($productId);
    $tierPrices = $product->getTierPrices();
    $arrayToSend = [];

    if(count($tierPrices) > 0){
        foreach($tierPrices as $tier){
            if($tier->getCustomerGroupId() == $custGroupId){
                array_push($arrayToSend, $tier->getData());
            }
        if(count($arrayToSend) == 0){
            array_push($arrayToSend, "Creating a new Special Price with given values because it doesnt exist already");
        }

    }

    return $arrayToSend;

}

And this then returns:

[
    {
        "extension_attributes": {},
        "customer_group_id": "1958",
        "value": "4.5000",
        "qty": "1.0000"
    }
]

The goal is to return all of the attributes so that I can then edit them and create new ones. Below is all the attributes when pulling directly from the product without filtering by getTierPrice() :

"tier_price": [
    {
        "price_id": "15924",
        "website_id": "0",
        "all_groups": "0",
        "cust_group": "14",
        "price": "3.0000",
        "price_qty": "1.0000",
        "percentage_value": null,
        "website_price": "3.0000"
    }
],

Any assistance with getting the remaining attributes would be appreciated.

Was it helpful?

Solution

Turns out I was going about it the wrong way. The way I figured out how to do it was by doing this:

$product = $this->_productRepository->get($productId);
$tierPrices = $product->getTierPrices();
$tierArray = [];
$arrayToSend = [];

$tierPrices = $product->getData('tier_price');
foreach($tierPrices as $tier){
    array_push($tierArray, $tier);
}

return $tierPrices[0]['price_id'];

When calling $tierPrices any tier price can be selected from the first array index and then any attribute can be selected from the second array index. If any further explanation is needed comment below.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top