Pregunta

My current model is:

<?php
namespace Vendor\Modulename\Model\Config;

class Taxes implements \Magento\Framework\Option\ArrayInterface
{
    protected $_tax;

    /**
    * to option array
    *
    * @return array
    */
    public function __construct(
        \Magento\Tax\Model\Calculation\Rate $taxModelConfig){
        $this->_tax = $taxModelConfig;
    }

    public function toOptionArray()
    {
        $taxes = Array();
        foreach($this->_tax->getCollection()->getData() as $tax){
            //echo '<pre>';var_dump($tax);echo '</pre>';
            array_push($taxes, ['value' => $tax['code'],'label' => $tax['code']]);
        }
        return $taxes;
    }
}

It lists all tax rules. Is there any similar (without direct database query) way to list all Product Tax Classes (like default "Taxable Goods")?

Thank you in advance for any help.

¿Fue útil?

Solución

protected $_taxClasses;
public function __construct(
    \Magento\Tax\Model\TaxClass\Source\Product $taxClasses){
    $this->_taxClasses = $taxClasses;
}

public function toOptionArray()
{
   return $this->_taxClasses->getAllOptions();

}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top