123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Weee\Model\ResourceModel;
- use Magento\Catalog\Model\Product;
- use Magento\Catalog\Model\Product\Condition\ConditionInterface;
- /**
- * Wee tax resource model
- *
- * @api
- * @since 100.0.2
- */
- class Tax extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
- {
- /**
- * @var \Magento\Framework\Stdlib\DateTime
- */
- protected $dateTime;
- /**
- * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
- * @param \Magento\Framework\Stdlib\DateTime $dateTime
- * @param string $connectionName
- */
- public function __construct(
- \Magento\Framework\Model\ResourceModel\Db\Context $context,
- \Magento\Framework\Stdlib\DateTime $dateTime,
- $connectionName = null
- ) {
- $this->dateTime = $dateTime;
- parent::__construct($context, $connectionName);
- }
- /**
- * Resource initialization
- *
- * @return void
- */
- protected function _construct()
- {
- $this->_init('weee_tax', 'value_id');
- }
- /**
- * Fetch one
- *
- * @param \Magento\Framework\DB\Select|string $select
- * @return string
- */
- public function fetchOne($select)
- {
- return $this->getConnection()->fetchOne($select);
- }
- /**
- * @param int $countryId
- * @param int $regionId
- * @param int $websiteId
- * @return boolean
- */
- public function isWeeeInLocation($countryId, $regionId, $websiteId)
- {
- // Check if there is a weee_tax for the country and region
- $attributeSelect = $this->getConnection()->select();
- $attributeSelect->from(
- $this->getTable('weee_tax'),
- 'value'
- )->where(
- 'website_id IN(?)',
- [$websiteId, 0]
- )->where(
- 'country = ?',
- $countryId
- )->where(
- 'state = ?',
- $regionId
- )->limit(
- 1
- );
- $value = $this->getConnection()->fetchOne($attributeSelect);
- if ($value) {
- return true;
- }
- return false;
- }
- /**
- * @param int $countryId
- * @param int $regionId
- * @param int $websiteId
- * @param int $storeId
- * @param int $entityId
- * @return array[]
- */
- public function fetchWeeeTaxCalculationsByEntity($countryId, $regionId, $websiteId, $storeId, $entityId)
- {
- $attributeSelect = $this->getConnection()->select();
- $attributeSelect->from(
- ['eavTable' => $this->getTable('eav_attribute')],
- ['eavTable.attribute_code', 'eavTable.attribute_id', 'eavTable.frontend_label']
- )->joinLeft(
- ['eavLabel' => $this->getTable('eav_attribute_label')],
- 'eavLabel.attribute_id = eavTable.attribute_id and eavLabel.store_id = ' .((int) $storeId),
- 'eavLabel.value as label_value'
- )->joinInner(
- ['weeeTax' => $this->getTable('weee_tax')],
- 'weeeTax.attribute_id = eavTable.attribute_id',
- 'weeeTax.value as weee_value'
- )->where(
- 'eavTable.frontend_input = ?',
- 'weee'
- )->where(
- 'weeeTax.website_id IN(?)',
- [$websiteId, 0]
- )->where(
- 'weeeTax.country = ?',
- $countryId
- )->where(
- 'weeeTax.state IN(?)',
- [$regionId, 0]
- )->where(
- 'weeeTax.entity_id = ?',
- (int)$entityId
- );
- $order = ['weeeTax.state ' . \Magento\Framework\DB\Select::SQL_DESC,
- 'weeeTax.website_id ' . \Magento\Framework\DB\Select::SQL_DESC];
- $attributeSelect->order($order);
- $values = $this->getConnection()->fetchAll($attributeSelect);
- if ($values) {
- return $values;
- }
- return [];
- }
- }
|