public function test_get_query_builder_for_entity_should_return_update_query()
 {
     $expectedSQL = 'UPDATE example_table SET id = :dcValue1, `name_in_db_one` = :dcValue2, `name_in_db_two` = :dcValue3 WHERE id = :dcValue1';
     $expectedSQLParams = ['dcValue1' => self::UPDATE_RECORD_BY_ID, 'dcValue2' => self::IMPORT_VALUE, 'dcValue3' => self::ANOTHER_IMPORT_VALUE];
     $givenData = [self::MODEL_FIELD_NAME => self::IMPORT_VALUE, self::ANOTHER_MODEL_FIELD_NAME => self::ANOTHER_IMPORT_VALUE];
     $builder = $this->SUT->getQueryBuilderForEntity($givenData, 'Shopware\\Models\\Article\\Article', self::UPDATE_RECORD_BY_ID);
     $this->assertEquals($expectedSQL, $builder->getSQL(), "SQL UPDATE statement wasn't generated correctly");
     $this->assertEquals($expectedSQLParams, $builder->getParameters(), "Parameters for query builder wasn't set correctly.");
 }
예제 #2
0
 /**
  * initialises the class properties
  */
 public function __construct()
 {
     $this->db = Shopware()->Db();
     $this->dbalHelper = DbalHelper::create();
     $this->validator = new PriceValidator();
     $this->dataManager = new PriceDataManager();
     $this->customerGroups = $this->getCustomerGroup();
 }
 /**
  * @param array $article
  * @param array $defaultValues
  * @param int $detailId
  * @param boolean $createDetail
  * @return array
  */
 private function createOrUpdateArticleDetail($article, $defaultValues, $detailId, $createDetail)
 {
     $article = $this->dataManager->setArticleVariantData($article, ArticleDataType::$articleVariantFieldsMapping);
     if ($createDetail) {
         $article = $this->dataManager->setDefaultFieldsForCreate($article, $defaultValues);
     }
     $builder = $this->dbalHelper->getQueryBuilderForEntity($article, 'Shopware\\Models\\Article\\Detail', $detailId);
     $builder->execute();
     if (!$detailId) {
         $detailId = $this->connection->lastInsertId();
     }
     return array($article, $detailId);
 }
 /**
  * @param array $record
  * @return string
  */
 private function getSupplierId($record)
 {
     $this->suppliers = $this->getSuppliers();
     $name = $record['supplierName'];
     $supplierId = $this->suppliers[$name];
     //creates supplier if does not exists
     if (!$supplierId) {
         $data = array('name' => $name);
         $builder = $this->dbalHelper->getQueryBuilderForEntity($data, 'Shopware\\Models\\Article\\Supplier', false);
         $builder->execute();
         $supplierId = $this->db->lastInsertId();
         $this->suppliers[$name] = $supplierId;
     }
     return $supplierId;
 }
예제 #5
0
 /**
  * @return \Shopware\Components\SwagImportExport\DataManagers\Articles\ArticleDataManager
  */
 protected function getArticleDataManager()
 {
     $proxyAdapter = Shopware()->Hooks()->getProxy('Shopware\\Components\\SwagImportExport\\DataManagers\\Articles\\ArticleDataManager');
     $db = Shopware()->Db();
     $dbalHelper = DbalHelper::create();
     return new $proxyAdapter($db, $dbalHelper);
 }
 /**
  * @param array $data
  * @return string
  */
 protected function createOption($data)
 {
     $builder = $this->dbalHelper->getQueryBuilderForEntity($data, 'Shopware\\Models\\Article\\Configurator\\Option', false);
     $builder->execute();
     return $this->connection->lastInsertId();
 }
 /**
  * @param string $entityName
  * @param array $data
  * @return string
  */
 private function createElement($entityName, $data)
 {
     $builder = $this->dbalHelper->getQueryBuilderForEntity($data, $entityName, false);
     $builder->execute();
     return $this->connection->lastInsertId();
 }