/**
  * @dataProvider insertDataProvider
  */
 public function testInsertMultiple($data)
 {
     $this->_connection->insertMultiple($this->_tableName, $data);
     $select = $this->_connection->select()->from($this->_tableName);
     $result = $this->_connection->fetchRow($select);
     $this->assertEquals($data, $result);
 }
Example #2
0
 /**
  * Insert multiple
  *
  * @param array $data
  * @return void
  * @throws \Magento\Framework\Exception\AlreadyExistsException
  * @throws \Exception
  */
 protected function insertMultiple($data)
 {
     try {
         $this->connection->insertMultiple($this->resource->getTableName(self::TABLE_NAME), $data);
     } catch (\Exception $e) {
         if ($e->getCode() === self::ERROR_CODE_DUPLICATE_ENTRY && preg_match('#SQLSTATE\\[23000\\]: [^:]+: 1062[^\\d]#', $e->getMessage())) {
             throw new \Magento\Framework\Exception\AlreadyExistsException(__('URL key for specified store already exists.'));
         }
         throw $e;
     }
 }
Example #3
0
 /**
  * Insert multiple
  *
  * @param array $data
  * @return void
  * @throws DuplicateEntryException
  * @throws \Exception
  */
 protected function insertMultiple($data)
 {
     try {
         $this->connection->insertMultiple($this->resource->getTableName(self::TABLE_NAME), $data);
     } catch (\Exception $e) {
         if ($e->getCode() === self::ERROR_CODE_DUPLICATE_ENTRY && preg_match('#SQLSTATE\\[23000\\]: [^:]+: 1062[^\\d]#', $e->getMessage())) {
             throw new DuplicateEntryException();
         }
         throw $e;
     }
 }
 /**
  * @inheritdoc
  */
 public function insertRecords($documentName, $records, $updateOnDuplicate = false)
 {
     $this->resourceAdapter->rawQuery("SET @OLD_INSERT_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
     if ($updateOnDuplicate) {
         $result = $this->resourceAdapter->insertOnDuplicate($documentName, $records);
     } else {
         $result = $this->resourceAdapter->insertMultiple($documentName, $records);
     }
     $this->resourceAdapter->rawQuery("SET SQL_MODE=IFNULL(@OLD_INSERT_SQL_MODE,'')");
     return $result;
 }
Example #5
0
 /**
  * @param Rule $rule
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function updateRuleProductData(Rule $rule)
 {
     $ruleId = $rule->getId();
     if ($rule->getProductsFilter()) {
         $this->connection->delete($this->getTable('catalogrule_product'), ['rule_id=?' => $ruleId, 'product_id IN (?)' => $rule->getProductsFilter()]);
     } else {
         $this->connection->delete($this->getTable('catalogrule_product'), $this->connection->quoteInto('rule_id=?', $ruleId));
     }
     if (!$rule->getIsActive()) {
         return $this;
     }
     $websiteIds = $rule->getWebsiteIds();
     if (!is_array($websiteIds)) {
         $websiteIds = explode(',', $websiteIds);
     }
     if (empty($websiteIds)) {
         return $this;
     }
     \Magento\Framework\Profiler::start('__MATCH_PRODUCTS__');
     $productIds = $rule->getMatchingProductIds();
     \Magento\Framework\Profiler::stop('__MATCH_PRODUCTS__');
     $customerGroupIds = $rule->getCustomerGroupIds();
     $fromTime = strtotime($rule->getFromDate());
     $toTime = strtotime($rule->getToDate());
     $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
     $sortOrder = (int) $rule->getSortOrder();
     $actionOperator = $rule->getSimpleAction();
     $actionAmount = $rule->getDiscountAmount();
     $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : '';
     $subActionAmount = $rule->getSubDiscountAmount();
     $actionStop = $rule->getStopRulesProcessing();
     $rows = [];
     foreach ($productIds as $productId => $validationByWebsite) {
         foreach ($websiteIds as $websiteId) {
             if (empty($validationByWebsite[$websiteId])) {
                 continue;
             }
             foreach ($customerGroupIds as $customerGroupId) {
                 $rows[] = ['rule_id' => $ruleId, 'from_time' => $fromTime, 'to_time' => $toTime, 'website_id' => $websiteId, 'customer_group_id' => $customerGroupId, 'product_id' => $productId, 'action_operator' => $actionOperator, 'action_amount' => $actionAmount, 'action_stop' => $actionStop, 'sort_order' => $sortOrder, 'sub_simple_action' => $subActionOperator, 'sub_discount_amount' => $subActionAmount];
                 if (count($rows) == $this->batchCount) {
                     $this->connection->insertMultiple($this->getTable('catalogrule_product'), $rows);
                     $rows = [];
                 }
             }
         }
     }
     if (!empty($rows)) {
         $this->connection->insertMultiple($this->getTable('catalogrule_product'), $rows);
     }
     return $this;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 protected function doAddMultiple($data)
 {
     $this->connection->insertMultiple(self::TABLE_NAME, $data);
 }
Example #7
0
 /**
  * Save custom option type values
  *
  * @param array $typeValues Option type values
  * @return $this
  */
 protected function _saveSpecificTypeValues(array $typeValues)
 {
     $this->_deleteSpecificTypeValues(array_keys($typeValues));
     $typeValueRows = array();
     foreach ($typeValues as $optionId => $optionInfo) {
         foreach ($optionInfo as $row) {
             $row['option_id'] = $optionId;
             $typeValueRows[] = $row;
         }
     }
     if ($typeValueRows) {
         $this->_connection->insertMultiple($this->_tables['catalog_product_option_type_value'], $typeValueRows);
     }
     return $this;
 }