/**
  * @param array $records
  * @throws \Exception
  */
 private function performImport($records)
 {
     $articleWriter = new ArticleWriter();
     $pricesWriter = new PriceWriter();
     $categoryWriter = new CategoryWriter();
     $configuratorWriter = ConfiguratorWriter::createFromGlobalSingleton();
     $translationWriter = new TranslationWriter();
     $propertyWriter = PropertyWriter::createFromGlobalSingleton();
     $relationWriter = new RelationWriter($this);
     $imageWriter = new ImageWriter($this);
     $defaultValues = $this->getDefaultValues();
     foreach ($records['article'] as $index => $article) {
         try {
             $this->modelManager->getConnection()->beginTransaction();
             $articleWriterResult = $articleWriter->write($article, $defaultValues);
             $processedFlag = isset($article['processed']) && $article['processed'] == 1;
             /**
              * Only processed data will be imported
              */
             if (!$processedFlag) {
                 $pricesWriter->write($articleWriterResult->getArticleId(), $articleWriterResult->getDetailId(), array_filter($records['price'], function ($price) use($index) {
                     return $price['parentIndexElement'] == $index;
                 }));
                 $categoryWriter->write($articleWriterResult->getArticleId(), array_filter($records['category'], function ($category) use($index) {
                     return $category['parentIndexElement'] == $index && ($category['categoryId'] || $category['categoryPath']);
                 }));
                 $configuratorWriter->writeOrUpdateConfiguratorSet($articleWriterResult, array_filter($records['configurator'], function ($configurator) use($index) {
                     return $configurator['parentIndexElement'] == $index;
                 }));
                 $propertyWriter->writeUpdateCreatePropertyGroupsFilterAndValues($articleWriterResult->getArticleId(), $article['orderNumber'], $this->filterPropertyValues($records, $index, $articleWriterResult));
                 $translationWriter->write($articleWriterResult->getArticleId(), $articleWriterResult->getDetailId(), $articleWriterResult->getMainDetailId(), array_filter($records['translation'], function ($translation) use($index) {
                     return $translation['parentIndexElement'] == $index;
                 }));
             }
             /**
              * Processed and unprocessed data will be imported
              */
             if ($processedFlag) {
                 $article['mainNumber'] = $article['orderNumber'];
             }
             $relationWriter->write($articleWriterResult->getArticleId(), $article['mainNumber'], array_filter($records['accessory'], function ($accessory) use($index, $articleWriterResult) {
                 return $accessory['parentIndexElement'] == $index && $articleWriterResult->getMainDetailId() == $articleWriterResult->getDetailId();
             }), 'accessory', $processedFlag);
             $relationWriter->write($articleWriterResult->getArticleId(), $article['mainNumber'], array_filter($records['similar'], function ($similar) use($index, $articleWriterResult) {
                 return $similar['parentIndexElement'] == $index && $articleWriterResult->getMainDetailId() == $articleWriterResult->getDetailId();
             }), 'similar', $processedFlag);
             $imageWriter->write($articleWriterResult->getArticleId(), $article['mainNumber'], array_filter($records['image'], function ($image) use($index) {
                 return $image['parentIndexElement'] == $index;
             }));
             $this->modelManager->getConnection()->commit();
         } catch (AdapterException $e) {
             $this->modelManager->getConnection()->rollBack();
             $message = $e->getMessage();
             $this->saveMessage($message);
         }
     }
 }
Beispiel #2
0
 /**
  * initialises the bootstrapPath variable
  *
  * @param $em
  * @param $soapApi
  * @param $config
  */
 public function __construct(ModelManager $em, SoapApi $soapApi, Config $config)
 {
     $this->db = $em->getConnection();
     $this->tsSoapApi = $soapApi;
     $this->tsConfig = $config;
     /** @var Repository $shopRepository */
     $shopRepository = $em->getRepository('Shopware\\Models\\Shop\\Shop');
     $this->shops = $shopRepository->getActiveShops(AbstractQuery::HYDRATE_ARRAY);
 }
Beispiel #3
0
 /**
  * @return \Shopware\Components\Model\DatabaseDriver
  */
 private function getDatabaseDriver()
 {
     $platform = $this->em->getConnection()->getDatabasePlatform();
     $platform->registerDoctrineTypeMapping('enum', 'string');
     $driver = new \Shopware\Components\Model\DatabaseDriver(
         $this->em->getConnection()->getSchemaManager()
     );
     return $driver;
 }
Beispiel #4
0
 /**
  * Returns the Trusted Shops config used in the frontend
  *
  * @param $shopId
  * @return array
  */
 public function getTrustedShopBasicConfig($shopId)
 {
     $config = $this->getSettings($shopId);
     $sql = "SELECT id, description\n\t\t\t\tFROM s_core_states\n\t\t\t\tWHERE description LIKE 'TS - Antrag%'\n\t\t\t\tORDER BY id";
     $states = $this->em->getConnection()->fetchAll($sql);
     //set trusted shop parameters
     $trustedShop = array('id' => $config['trustedShopsId'], 'rating_active' => $config['trustedShopsShowRatingWidget'], 'rating_buttons' => $config['trustedShopsShowRatingsButtons'], 'rating_link' => $this->getRatingLink($config['trustedShopsId']), 'rate_later_days' => $config['trustedShopsRateLaterDays'], 'user' => $config['trustedShopsUser'], 'pw' => $config['trustedShopsPassword'], 'trustBadgeCode' => $config['trustedShopsTrustBadgeCode'], 'stateWaiting' => $states[0], 'stateSuccess' => $states[1], 'stateError' => $states[2]);
     return $trustedShop;
 }
 /**
  * Returns orders' ids. Executed during `prepareExport`.
  *
  * @param int $start
  * @param int $limit
  * @param array $filter
  * @return array
  */
 public function readRecordIds($start = null, $limit = null, $filter = null)
 {
     $connection = $this->modelManager->getConnection();
     /* @var \Doctrine\DBAL\Query\QueryBuilder */
     $builder = $connection->createQueryBuilder();
     $builder->select('id')->from('s_order');
     if (isset($filter['orderstate']) && is_numeric($filter['orderstate'])) {
         $builder->andWhere('status = :orderstate');
         $builder->setParameter('orderstate', $filter['orderstate']);
     }
     if (isset($filter['paymentstate']) && is_numeric($filter['paymentstate'])) {
         $builder->andWhere('cleared = :paymentstate');
         $builder->setParameter('paymentstate', $filter['paymentstate']);
     }
     if (isset($filter['ordernumberFrom']) && is_numeric($filter['ordernumberFrom'])) {
         $builder->andWhere('ordernumber > :orderNumberFrom');
         $builder->setParameter('orderNumberFrom', $filter['ordernumberFrom']);
     }
     if (isset($filter['dateFrom']) && $filter['dateFrom']) {
         $dateFrom = $filter['dateFrom'];
         $dateFrom->setTime(0, 0, 0);
         $builder->andWhere('ordertime >= :dateFrom');
         $builder->setParameter('dateFrom', $dateFrom->format('Y-m-d H:i:s'));
     }
     if (isset($filter['dateTo']) && $filter['dateTo']) {
         $dateTo = $filter['dateTo'];
         $builder->andWhere('ordertime <= :dateTo');
         $builder->setParameter('dateTo', $dateTo->format('Y-m-d H:i:s'));
     }
     if ($start) {
         $builder->setFirstResult($start);
     }
     if ($limit) {
         $builder->setMaxResults($limit);
     }
     $ids = $builder->execute()->fetchAll(\PDO::FETCH_COLUMN);
     return is_array($ids) ? $ids : [];
 }
Beispiel #6
0
 /**
  * Delete resource and its privileges from database
  * @param $resourceName
  * @return bool
  */
 public function deleteResource($resourceName)
 {
     $repository = $this->em->getRepository('Shopware\\Models\\User\\Resource');
     /** @var $resource \Shopware\Models\User\Resource */
     $resource = $repository->findOneBy(array("name" => $resourceName));
     if (empty($resource)) {
         return false;
     }
     // remove the resource flag in the s_core_menu manually.
     $this->em->getConnection()->executeUpdate("UPDATE s_core_menu SET resourceID = NULL WHERE resourceID = ?", [$resource->getId()]);
     //The mapping table s_core_acl_roles must be cleared manually.
     $this->em->getConnection()->executeUpdate("DELETE FROM s_core_acl_roles WHERE resourceID = ?", [$resource->getId()]);
     //The privileges will be removed automatically
     $this->em->remove($resource);
     $this->em->flush();
     return true;
 }
Beispiel #7
0
 /**
  * initialises $em as ModelManager
  * initialises $db as DB component
  *
  * @param ModelManager $em
  */
 public function __construct(ModelManager $em)
 {
     $this->em = $em;
     $this->db = $em->getConnection();
 }
 /**
  * ExtendedEntityManager constructor.
  * @param ModelManager $em
  */
 public function __construct(ModelManager $em)
 {
     parent::__construct($em->getConnection(), $em->getConfiguration(), $em->getEventManager());
 }
 /**
  * @param int $detailId
  * @return bool|string
  */
 protected function getArticleDetailActiveFlag($detailId)
 {
     $connection = $this->modelManager->getConnection();
     return $connection->executeQuery('SELECT active FROM s_articles_details WHERE id = ?', [$detailId])->fetchColumn();
 }
 /**
  * @param ModelManager $em
  * @param ContextServiceInterface $contextService
  */
 public function __construct(ModelManager $em, ContextServiceInterface $contextService)
 {
     $this->em = $em;
     $this->connection = $this->em->getConnection();
     $this->contextService = $contextService;
 }