0

What is the alternative method of following Magento 1 for Magento 2

Mage::helper("tax")->getAllRatesByProductClass()
Kaushal Suthar
  • 3,227
  • 5
  • 31
  • 57

2 Answers2

0

Please see Alan Storms answer here: https://magento.stackexchange.com/a/10572/5769

tecjam
  • 4,033
  • 3
  • 27
  • 48
0

I've found that method flagged as obsolete in file vendor/magento/magento2-base/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

Looking at the comments in Magento1 original...

/**
 * Get all tax rates JSON for all product tax classes of specific store
 *
 * array(
 *      value_{$productTaxVlassId} => $rate
 * )
 *
 * @param mixed $store
 * @return string
 */

Take a look at Magento\Tax\Model\TaxCalculation class, as it seems this method does something similar (although you'll need to collect product tax classes before)

/**
 * Calculate rate based on default parameter
 *
 * @param int $productTaxClassID
 * @param int|null $customerId
 * @param string|null $storeId
 * @param bool $isDefault
 * @return float
 */
protected function getRate(
    $productTaxClassID,
    $customerId = null,
    $storeId = null,
    $isDefault = false
) {
    if ($storeId === null) {
        $storeId = $this->storeManager->getStore()->getStoreId();
    }
    if (!$isDefault) {
        $addressRequestObject = $this->calculationTool->getRateRequest(null, null, null, $storeId, $customerId);
    } else {
        $addressRequestObject = $this->calculationTool->getDefaultRateRequest($storeId, $customerId);
    }
    $addressRequestObject->setProductClassId($productTaxClassID);
    return $this->calculationTool->getRate($addressRequestObject);
}

Good luck!

Raul Sanchez
  • 3,036
  • 3
  • 28
  • 63