Esempio n. 1
0
 /**
  * @return \Magento\Framework\DB\Adapter\AdapterInterface
  */
 protected function getConnection()
 {
     if (!$this->connection) {
         $this->connection = $this->resource->getConnection('sales');
     }
     return $this->connection;
 }
 /**
  * Returns Adapter interface
  *
  * @return array \Magento\Framework\DB\Adapter\AdapterInterface
  */
 public function getConnection()
 {
     if (!$this->connection) {
         $this->connection = $this->resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);
     }
     return $this->connection;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function install(array $fixtures)
 {
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */
     $adapter = $this->resource->getConnection('core_write');
     $regions = $this->loadDirectoryRegions();
     foreach ($fixtures as $fileName) {
         $fileName = $this->fixtureManager->getFixture($fileName);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fileName);
         $header = array_shift($rows);
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0;
             try {
                 $adapter->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsite()->getId(), 'dest_country_id' => $data['country'], 'dest_region_id' => $regionId, 'dest_zip' => $data['zip'], 'condition_name' => 'package_value', 'condition_value' => $data['order_subtotal'], 'price' => $data['price'], 'cost' => 0]);
             } catch (\Zend_Db_Statement_Exception $e) {
                 if ($e->getCode() == self::ERROR_CODE_DUPLICATE_ENTRY) {
                     // In case if Sample data was already installed we just skip duplicated records installation
                     continue;
                 } else {
                     throw $e;
                 }
             }
         }
     }
     $this->configWriter->save('carriers/tablerate/active', 1);
     $this->configWriter->save('carriers/tablerate/condition_name', 'package_value');
     $this->cacheTypeList->cleanType('config');
 }
Esempio n. 4
0
 /**
  * Get connection object
  *
  * @return \Magento\Framework\DB\Adapter\AdapterInterface
  */
 public function getConnection()
 {
     if (null === $this->connection) {
         $this->connection = $this->resourceModel->getConnection($this->connectionName);
     }
     return $this->connection;
 }
Esempio n. 5
0
 /**
  * @return void
  */
 protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->resource = $this->objectManager->get('Magento\\Framework\\App\\ResourceConnection');
     $this->connection = $this->resource->getConnection();
     $this->reviewCollection = $this->objectManager->create('Magento\\Review\\Model\\ResourceModel\\Review\\Collection');
     $this->reviewResource = $this->objectManager->create('Magento\\Review\\Model\\ResourceModel\\Review');
 }
 /**
  * {@inheritdoc}
  */
 public function build($productId)
 {
     $timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
     $currentDate = $this->dateTime->formatDate($timestamp, false);
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     $productTable = $this->resource->getTableName('catalog_product_entity');
     return [$this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $this->resource->getTableName('catalogrule_product_price')], 't.product_id = child.entity_id', [])->where('parent.entity_id = ? ', $productId)->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())->where('t.rule_date = ?', $currentDate)->order('t.rule_price ' . Select::SQL_ASC)->limit(1)];
 }
Esempio n. 7
0
 public function getConnection($name = null)
 {
     if (is_null($name)) {
         $name = \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION;
     }
     $result = $this->_resource->getConnection($name);
     return $result;
 }
Esempio n. 8
0
 /**
  * @return void
  */
 public function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->resource = $this->objectManager->get('Magento\\Framework\\App\\ResourceConnection');
     $this->connection = $this->resource->getConnection();
     $this->model = $this->objectManager->create('Magento\\Framework\\Mview\\View\\Changelog', ['resource' => $this->resource]);
     $this->model->setViewId('test_view_id_1');
     $this->model->create();
 }
 /**
  * @param array $ids
  * @return array
  */
 public function getIds(array $ids)
 {
     $key = md5(json_encode($ids));
     if (!isset($this->productIds[$key])) {
         $connection = $this->resource->getConnection();
         $this->productIds[$key] = $connection->fetchCol($connection->select()->from(['e' => $this->resource->getTableName('catalog_product_entity')], ['e.entity_id'])->where('e.type_id = ?', \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE)->where('e.entity_id IN (?)', $ids));
     }
     return $this->productIds[$key];
 }
Esempio n. 10
0
 protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     /** @var \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry */
     $indexerRegistry = $this->objectManager->create('\\Magento\\Framework\\Indexer\\IndexerRegistry');
     $this->indexer = $indexerRegistry->get('catalogsearch_fulltext');
     $this->resource = $this->objectManager->get('Magento\\Framework\\App\\ResourceConnection');
     $this->connectionMock = $this->resource->getConnection();
 }
 /**
  * @param Collection $productCollection
  * @param bool $printQuery
  * @param bool $logQuery
  * @return array
  */
 public function beforeLoad(Collection $productCollection, $printQuery = false, $logQuery = false)
 {
     if (!$productCollection->hasFlag('catalog_rule_loaded')) {
         $connection = $this->resource->getConnection();
         $store = $this->storeManager->getStore();
         $productCollection->getSelect()->joinLeft(['catalog_rule' => $this->resource->getTableName('catalogrule_product_price')], implode(' AND ', ['catalog_rule.product_id = e.entity_id', $connection->quoteInto('catalog_rule.website_id = ?', $store->getWebsiteId()), $connection->quoteInto('catalog_rule.customer_group_id = ?', $this->customerSession->getCustomerGroupId()), $connection->quoteInto('catalog_rule.rule_date = ?', $this->dateTime->formatDate($this->localeDate->scopeDate($store->getId()), false))]), [CatalogRulePrice::PRICE_CODE => 'rule_price']);
         $productCollection->setFlag('catalog_rule_loaded', true);
     }
     return [$printQuery, $logQuery];
 }
Esempio n. 12
0
 /**
  * @param int $n
  * @return void
  */
 public function generateSequences($n = 10)
 {
     $connection = $this->appResource->getConnection();
     for ($i = 0; $i < $n; $i++) {
         foreach ($this->entities as $entityName) {
             $sequenceName = $this->appResource->getTableName(sprintf('sequence_%s_%s', $entityName, $i));
             if (!$connection->isTableExists($sequenceName)) {
                 $connection->query($this->ddlSequence->getCreateSequenceDdl($sequenceName));
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getProducts(ProductInterface $product)
 {
     if (!isset($this->products[$product->getId()])) {
         if ($this->requestSafety->isSafeMethod()) {
             $productIds = $this->resource->getConnection()->fetchCol('(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')');
             $this->products[$product->getId()] = $this->collectionFactory->create()->addAttributeToSelect(['price', 'special_price'])->addIdFilter($productIds);
         } else {
             $this->products[$product->getId()] = $this->configurable->getUsedProducts($product);
         }
     }
     return $this->products[$product->getId()];
 }
Esempio n. 14
0
 /**
  * Move data from temporary tables to flat
  *
  * @param string $flatTable
  * @param string $flatDropName
  * @param string $temporaryFlatTableName
  * @return void
  */
 public function move($flatTable, $flatDropName, $temporaryFlatTableName)
 {
     $connection = $this->_resource->getConnection();
     $renameTables = [];
     if ($connection->isTableExists($flatTable)) {
         $renameTables[] = ['oldName' => $flatTable, 'newName' => $flatDropName];
     }
     $renameTables[] = ['oldName' => $temporaryFlatTableName, 'newName' => $flatTable];
     $connection->dropTable($flatDropName);
     $connection->renameTablesBatch($renameTables);
     $connection->dropTable($flatDropName);
 }
 /**
  * {@inheritdoc}
  */
 public function build($productId)
 {
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     $productTable = $this->resource->getTableName('catalog_product_entity');
     $priceSelect = $this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $this->resource->getTableName('catalog_product_entity_tier_price')], "t.{$linkField} = child.{$linkField}", [])->where('parent.entity_id = ? ', $productId)->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())->where('t.qty = ?', 1)->order('t.value ' . Select::SQL_ASC)->limit(1);
     $priceSelectDefault = clone $priceSelect;
     $priceSelectDefault->where('t.website_id = ?', self::DEFAULT_WEBSITE_ID);
     $select[] = $priceSelectDefault;
     if (!$this->catalogHelper->isPriceGlobal()) {
         $priceSelect->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId());
         $select[] = $priceSelect;
     }
     return $select;
 }
 public function __construct($name = null, array $data = [], $dataName = '')
 {
     parent::__construct($name, $data, $dataName);
     $this->_manObj = ObjectManager::getInstance();
     $this->_logger = $this->_manObj->get(\Psr\Log\LoggerInterface::class);
     $this->_resource = $this->_manObj->get(\Magento\Framework\App\ResourceConnection::class);
     $this->_conn = $this->_resource->getConnection();
     $this->_toolPeriod = $this->_manObj->get(IPeriod::class);
     /* base services */
     $this->_callDownlineCustomer = $this->_manObj->get(\Praxigento\Downline\Service\ICustomer::class);
     $this->_callDownlineSnap = $this->_manObj->get(\Praxigento\Downline\Service\ISnap::class);
     /* set up application */
     $this->_setAreaCode();
 }
 /**
  * {@inheritdoc}
  */
 public function build($productId)
 {
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     $priceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'price');
     $productTable = $this->resource->getTableName('catalog_product_entity');
     $priceSelect = $this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $priceAttribute->getBackendTable()], "t.{$linkField} = child.{$linkField}", [])->where('parent.entity_id = ? ', $productId)->where('t.attribute_id = ?', $priceAttribute->getAttributeId())->where('t.value IS NOT NULL')->order('t.value ' . Select::SQL_ASC)->limit(1);
     $priceSelectDefault = clone $priceSelect;
     $priceSelectDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
     $select[] = $priceSelectDefault;
     if (!$this->catalogHelper->isPriceGlobal()) {
         $priceSelect->where('t.store_id = ?', $this->storeManager->getStore()->getId());
         $select[] = $priceSelect;
     }
     return $select;
 }
Esempio n. 18
0
 /**
  * Create sequence with metadata and profile
  *
  * @throws \Exception
  * @throws \Magento\Framework\Exception\AlreadyExistsException
  * @return void
  */
 public function create()
 {
     $metadata = $this->resourceMetadata->loadByEntityTypeAndStore($this->data['entity_type'], $this->data['store_id']);
     if ($metadata->getSequenceTable() == $this->getSequenceName()) {
         return;
     }
     $this->data['sequence_table'] = $this->getSequenceName();
     $this->data['is_active'] = 1;
     $profile = $this->profileFactory->create(['data' => array_intersect_key($this->data, array_flip(['prefix', 'suffix', 'start_value', 'step', 'max_value', 'warning_value', 'is_active', 'active_profile']))]);
     $profile->setHasDataChanges(true);
     $this->data['active_profile'] = $profile;
     $metadata = $this->metaFactory->create(['data' => array_intersect_key($this->data, array_flip(['entity_type', 'store_id', 'sequence_table', 'active_profile']))]);
     $metadata->setHasDataChanges(true);
     try {
         $this->resourceMetadata->save($metadata);
         $connection = $this->appResource->getConnection('sales');
         if (!$connection->isTableExists($this->data['sequence_table'])) {
             $connection->query($this->ddlSequence->getCreateSequenceDdl($this->data['sequence_table'], $this->data['start_value']));
         }
     } catch (Exception $e) {
         $this->resourceMetadata->delete($metadata);
         $this->logger->critical($e);
         throw $e;
     }
     $this->data = array_flip($this->pattern);
 }
Esempio n. 19
0
 /**
  * Constructor
  *
  * @param ResourceConnection $resource
  * @param TextHelper         $textHelper
  * @param Damerau            $damerau
  */
 public function __construct(ResourceConnection $resource, TextHelper $textHelper, Damerau $damerau)
 {
     $this->resource = $resource;
     $this->connection = $resource->getConnection();
     $this->damerau = $damerau;
     $this->text = $textHelper;
 }
Esempio n. 20
0
 /**
  * @param \Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper
  * @param \Magento\Framework\App\ResourceConnection $resource
  * @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
  */
 public function __construct(\Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper, \Magento\Framework\App\ResourceConnection $resource, \Magento\Framework\Model\Entity\MetadataPool $metadataPool)
 {
     $this->_productIndexerHelper = $productIndexerHelper;
     $this->resource = $resource;
     $this->_connection = $resource->getConnection();
     $this->metadataPool = $metadataPool;
 }
 /**
  * @param \Magento\Framework\App\ResourceConnection $resource
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Catalog\Model\Config $config
  */
 public function __construct(\Magento\Framework\App\ResourceConnection $resource, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Config $config)
 {
     $this->resource = $resource;
     $this->connection = $resource->getConnection();
     $this->storeManager = $storeManager;
     $this->config = $config;
 }
 /**
  * Get quote table description.
  *
  * @return array
  */
 public function getQuoteTableDescription()
 {
     $quoteTable = $this->adapter->getTableName('quote');
     $adapter = $this->adapter->getConnection('read');
     $columns = $adapter->describeTable($quoteTable);
     return $columns;
 }
Esempio n. 23
0
 /**
  * Tool constructor.
  */
 public function __construct(\Magento\Framework\App\ResourceConnection $resource, \Psr\Log\LoggerInterface $logger, \Praxigento\Core\Setup\Dem\Parser $parser)
 {
     $this->_resource = $resource;
     $this->_conn = $resource->getConnection();
     $this->_logger = $logger;
     $this->_parser = $parser;
 }
 /**
  * @param \Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper
  * @param \Magento\Framework\App\ResourceConnection $resource
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param TableDataInterface $tableData
  */
 public function __construct(\Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper, \Magento\Framework\App\ResourceConnection $resource, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Indexer\Product\Flat\TableDataInterface $tableData)
 {
     $this->_productIndexerHelper = $productIndexerHelper;
     $this->_connection = $resource->getConnection();
     $this->_config = $config;
     $this->_storeManager = $storeManager;
     $this->_tableData = $tableData;
 }
Esempio n. 25
0
 /**
  * @param Config $eavConfig
  * @param ResourceConnection $resource
  * @param ScopeResolverInterface $scopeResolver
  * @param Session $customerSession
  */
 public function __construct(Config $eavConfig, ResourceConnection $resource, ScopeResolverInterface $scopeResolver, Session $customerSession)
 {
     $this->eavConfig = $eavConfig;
     $this->resource = $resource;
     $this->connection = $resource->getConnection();
     $this->scopeResolver = $scopeResolver;
     $this->customerSession = $customerSession;
 }
Esempio n. 26
0
 /**
  * Validate sequence before save
  *
  * @throws \Magento\Framework\Exception\AlreadyExistsException
  * @return void
  */
 protected function validate()
 {
     $metadata = $this->resourceMetadata->loadByEntityTypeAndStore($this->data['entity_type'], $this->data['store_id']);
     $connection = $this->appResource->getConnection();
     if ($metadata->getId() && !$connection->isTableExists($this->getSequenceName())) {
         throw new \Magento\Framework\Exception\AlreadyExistsException(__('Sequence with this metadata already exists'));
     }
 }
Esempio n. 27
0
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  * @param \Magento\UrlRewrite\Helper\UrlRewrite $urlRewriteHelper
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param ResourceConnection $appResource
  * @param \Magento\UrlRewrite\Model\UrlFinderInterface $urlFinder
  * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
  * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
  * @param array $data
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\UrlRewrite\Helper\UrlRewrite $urlRewriteHelper, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\ResourceConnection $appResource, \Magento\UrlRewrite\Model\UrlFinderInterface $urlFinder, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
 {
     parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
     $this->urlRewriteHelper = $urlRewriteHelper;
     $this->connection = $appResource->getConnection();
     $this->urlFinder = $urlFinder;
     $this->storeManager = $storeManager;
 }
Esempio n. 28
0
 /**
  * @param ResourceConnection $resource
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
  */
 public function __construct(ResourceConnection $resource, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper)
 {
     $this->resource = $resource;
     $this->connection = $resource->getConnection();
     $this->storeManager = $storeManager;
     $this->resourceHelper = $resourceHelper;
     $this->columns = array_merge($this->getStaticColumns(), $this->getEavColumns());
 }
Esempio n. 29
0
 /**
  * @param ResourceConnection $resource
  * @param Range $range
  * @param Session $customerSession
  * @param MysqlDataProviderInterface $dataProvider
  * @param IntervalFactory $intervalFactory
  */
 public function __construct(ResourceConnection $resource, Range $range, Session $customerSession, MysqlDataProviderInterface $dataProvider, IntervalFactory $intervalFactory)
 {
     $this->resource = $resource;
     $this->connection = $resource->getConnection();
     $this->range = $range;
     $this->customerSession = $customerSession;
     $this->dataProvider = $dataProvider;
     $this->intervalFactory = $intervalFactory;
 }
Esempio n. 30
0
 public function __construct(ConfigHelper $configHelper, Logger $logger, ResourceConnection $resourceConnection, ObjectManagerInterface $objectManager)
 {
     $this->configHelper = $configHelper;
     $this->logger = $logger;
     $this->table = $resourceConnection->getTableName('algoliasearch_queue');
     $this->db = $resourceConnection->getConnection('core_write');
     $this->objectManager = $objectManager;
     $this->elementsPerPage = $this->configHelper->getNumberOfElementByPage();
 }