문제

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.

도움이 되었습니까?

해결책

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

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

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top