123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Weee\Model\ResourceModel\Attribute\Backend\Weee;
- /**
- * Catalog product WEEE tax backend attribute model
- *
- * @author Magento Core Team <core@magentocommerce.com>
- */
- class Tax extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
- {
- /**
- * @var \Magento\Store\Model\StoreManagerInterface
- */
- protected $_storeManager;
- /**
- * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param string $connectionName
- */
- public function __construct(
- \Magento\Framework\Model\ResourceModel\Db\Context $context,
- \Magento\Store\Model\StoreManagerInterface $storeManager,
- $connectionName = null
- ) {
- $this->_storeManager = $storeManager;
- parent::__construct($context, $connectionName);
- }
- /**
- * Defines main resource table and table identifier field
- *
- * @return void
- */
- protected function _construct()
- {
- $this->_init('weee_tax', 'value_id');
- }
- /**
- * Load product data
- *
- * @param \Magento\Catalog\Model\Product $product
- * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute
- * @return array
- */
- public function loadProductData($product, $attribute)
- {
- $select = $this->getConnection()->select()->from(
- $this->getMainTable(),
- ['website_id', 'country', 'state', 'value']
- )->where(
- 'entity_id = ?',
- (int)$product->getId()
- )->where(
- 'attribute_id = ?',
- (int)$attribute->getId()
- );
- if ($attribute->isScopeGlobal()) {
- $select->where('website_id = ?', 0);
- } else {
- $storeId = $product->getStoreId();
- if ($storeId) {
- $select->where(
- 'website_id IN (?)',
- [0, $this->_storeManager->getStore($storeId)->getWebsiteId()]
- );
- }
- }
- return $this->getConnection()->fetchAll($select);
- }
- /**
- * Delete product data
- *
- * @param \Magento\Catalog\Model\Product $product
- * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute
- * @return $this
- */
- public function deleteProductData($product, $attribute)
- {
- $where = ['entity_id = ?' => (int)$product->getId(), 'attribute_id = ?' => (int)$attribute->getId()];
- $connection = $this->getConnection();
- if (!$attribute->isScopeGlobal()) {
- $storeId = $product->getStoreId();
- if ($storeId) {
- $where['website_id IN(?)'] = [0, $this->_storeManager->getStore($storeId)->getWebsiteId()];
- }
- }
- $connection->delete($this->getMainTable(), $where);
- return $this;
- }
- /**
- * Insert product data
- *
- * @param \Magento\Catalog\Model\Product $product
- * @param array $data
- * @return $this
- */
- public function insertProductData($product, $data)
- {
- $data['entity_id'] = (int)$product->getId();
- $this->getConnection()->insert($this->getMainTable(), $data);
- return $this;
- }
- }
|