Question

I want get all list tax classes like below images in frontend. But, I don't know where is magento 2 save model for tax classes data.

enter image description here

Thanks

Was it helpful?

Solution

use Magento\Tax\Model\TaxClass\Source\Product as ProductTaxClassSource;

/**
 * @var ProductTaxClassSource
 */
protected $productTaxClassSource;


 /**     
 * @param ProductTaxClassSource $productTaxClassSource     
 */
public function __construct(        
    ProductTaxClassSource $productTaxClassSource,        
) {

    $this->productTaxClassSource = $productTaxClassSource;

}

Now you can use this like,

$taxClassess = $this->productTaxClassSource->getAllOptions()

Using objectManager (Not recommended)

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$taxClassObj = $objectManager->create('Magento\Tax\Model\TaxClass\Source\Product');
$taxClassess = $taxClassObj->getAllOptions()
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top