Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Tax.php
Go to the documentation of this file.
1 <?php
7 
10 
18 {
22  protected $dateTime;
23 
29  public function __construct(
30  \Magento\Framework\Model\ResourceModel\Db\Context $context,
31  \Magento\Framework\Stdlib\DateTime $dateTime,
32  $connectionName = null
33  ) {
34  $this->dateTime = $dateTime;
35  parent::__construct($context, $connectionName);
36  }
37 
43  protected function _construct()
44  {
45  $this->_init('weee_tax', 'value_id');
46  }
47 
54  public function fetchOne($select)
55  {
56  return $this->getConnection()->fetchOne($select);
57  }
58 
65  public function isWeeeInLocation($countryId, $regionId, $websiteId)
66  {
67  // Check if there is a weee_tax for the country and region
68  $attributeSelect = $this->getConnection()->select();
69  $attributeSelect->from(
70  $this->getTable('weee_tax'),
71  'value'
72  )->where(
73  'website_id IN(?)',
74  [$websiteId, 0]
75  )->where(
76  'country = ?',
77  $countryId
78  )->where(
79  'state = ?',
80  $regionId
81  )->limit(
82  1
83  );
84 
85  $value = $this->getConnection()->fetchOne($attributeSelect);
86  if ($value) {
87  return true;
88  }
89 
90  return false;
91  }
92 
101  public function fetchWeeeTaxCalculationsByEntity($countryId, $regionId, $websiteId, $storeId, $entityId)
102  {
103  $attributeSelect = $this->getConnection()->select();
104  $attributeSelect->from(
105  ['eavTable' => $this->getTable('eav_attribute')],
106  ['eavTable.attribute_code', 'eavTable.attribute_id', 'eavTable.frontend_label']
107  )->joinLeft(
108  ['eavLabel' => $this->getTable('eav_attribute_label')],
109  'eavLabel.attribute_id = eavTable.attribute_id and eavLabel.store_id = ' .((int) $storeId),
110  'eavLabel.value as label_value'
111  )->joinInner(
112  ['weeeTax' => $this->getTable('weee_tax')],
113  'weeeTax.attribute_id = eavTable.attribute_id',
114  'weeeTax.value as weee_value'
115  )->where(
116  'eavTable.frontend_input = ?',
117  'weee'
118  )->where(
119  'weeeTax.website_id IN(?)',
120  [$websiteId, 0]
121  )->where(
122  'weeeTax.country = ?',
123  $countryId
124  )->where(
125  'weeeTax.state IN(?)',
126  [$regionId, 0]
127  )->where(
128  'weeeTax.entity_id = ?',
129  (int)$entityId
130  );
131 
132  $order = ['weeeTax.state ' . \Magento\Framework\DB\Select::SQL_DESC,
133  'weeeTax.website_id ' . \Magento\Framework\DB\Select::SQL_DESC];
134  $attributeSelect->order($order);
135 
136  $values = $this->getConnection()->fetchAll($attributeSelect);
137 
138  if ($values) {
139  return $values;
140  }
141 
142  return [];
143  }
144 }
$order
Definition: order.php:55
$values
Definition: options.phtml:88
fetchWeeeTaxCalculationsByEntity($countryId, $regionId, $websiteId, $storeId, $entityId)
Definition: Tax.php:101
$value
Definition: gender.phtml:16
isWeeeInLocation($countryId, $regionId, $websiteId)
Definition: Tax.php:65
const SQL_DESC
Definition: Select.php:82
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Stdlib\DateTime $dateTime, $connectionName=null)
Definition: Tax.php:29