Esempio n. 1
0
 /**
  * @return bool
  */
 public function deleteAllCategories()
 {
     $sql = 'SELECT category_id
             FROM s_core_shops';
     $shopCategoriesIds = $this->db->fetchCol($sql);
     //don't delete shop's categories
     if (empty($shopCategoriesIds)) {
         $sql = 'TRUNCATE s_categories';
     } else {
         $ids = 'id != ' . implode(' AND id != ', $shopCategoriesIds);
         $sql = 'DELETE FROM s_categories
                 WHERE parent IS NOT NULL
                   AND ' . $ids;
     }
     if ($this->db->exec($sql) === false) {
         return false;
     }
     if ($this->db->exec('TRUNCATE s_articles_categories') === false) {
         return false;
     }
     if ($this->db->exec('TRUNCATE s_emarketing_banners') === false) {
         return false;
     }
     $sql = 'SELECT MAX(category_id)
             FROM s_core_shops';
     $lastCategoryId = $this->db->fetchOne($sql);
     $auto_increment = empty($lastCategoryId) ? 2 : $lastCategoryId + 1;
     $sql = 'ALTER TABLE s_categories AUTO_INCREMENT = ' . $auto_increment;
     if ($this->db->exec($sql) === false) {
         return false;
     }
     return true;
 }
Esempio n. 2
0
 /**
  * @covers sBasket::sDeleteNote
  * @depends testsCountNotes
  */
 public function testsDeleteNote($input)
 {
     list($randomArticles, $cookieId) = $input;
     $_COOKIE["sUniqueID"] = $cookieId;
     // Null argument, return null
     $this->assertFalse($this->module->sDeleteNote(null));
     // Get random article that's not in the basket
     $randomNotPresentArticleId = $this->db->fetchOne('SELECT detail.id FROM s_articles_details detail
         INNER JOIN s_articles article
           ON article.id = detail.articleID
         WHERE detail.active = 1
         AND detail.id NOT IN (?)
         ORDER BY RAND() LIMIT 1', array(array_column($randomArticles, 'id')));
     // Check that we currently have 2 articles
     $this->assertEquals(2, $this->module->sCountNotes());
     // Get true even if article is not in the wishlist
     $this->assertTrue($this->module->sDeleteNote($randomNotPresentArticleId));
     // Check that we still have 2 articles
     $this->assertEquals(2, $this->module->sCountNotes());
     $noteIds = $this->db->fetchCol('SELECT id FROM s_order_notes detail
         WHERE sUniqueID = ?', array($this->module->sSYSTEM->_COOKIE["sUniqueID"]));
     // Get true even if article is not in the wishlist
     $this->assertTrue($this->module->sDeleteNote($noteIds[0]));
     // Check that we now have 1 article
     $this->assertEquals(1, $this->module->sCountNotes());
     // Get true even if article is not in the wishlist
     $this->assertTrue($this->module->sDeleteNote($noteIds[1]));
     // Check that we now have an empty wishlist
     $this->assertEquals(0, $this->module->sCountNotes());
 }
Esempio n. 3
0
 /**
  * @param int $articleID
  * @return bool
  */
 private function deleteDownloads($articleID)
 {
     /* @var ArticleRepository $articleRepository */
     $articleRepository = $this->getArticleRepository();
     $article = $articleRepository->find($articleID);
     if (!$article instanceof Article) {
         return false;
     }
     $downloads = $article->getDownloads();
     foreach ($downloads as $downloadModel) {
         $filename = $downloadModel->getFile();
         $this->em->remove($downloadModel);
         /* @var MediaRepository $mediaRepository */
         $mediaRepository = $this->getMediaRepository();
         $mediaList = $mediaRepository->findBy(['path' => $filename]);
         foreach ($mediaList as $mediaModel) {
             $this->em->remove($mediaModel);
         }
     }
     $sql = 'SELECT id FROM s_articles_downloads WHERE articleID = ' . $articleID;
     $downloads = $this->db->fetchCol($sql);
     if (!empty($downloads)) {
         $this->deleteTranslation('download', $downloads);
     }
     $this->em->flush();
     return true;
 }
Esempio n. 4
0
 /**
  * Get articleId of all products from cart
  * Used in CheckoutController
  *
  * @return array|null List of article ids in current basket, or null if none
  */
 public function sGetBasketIds()
 {
     $articles = $this->db->fetchCol('SELECT DISTINCT articleID
             FROM s_order_basket
             WHERE sessionID = ?
             AND modus = 0
             ORDER BY modus ASC, datum DESC', array($this->session->get('sessionId')));
     return empty($articles) ? null : $articles;
 }
Esempio n. 5
0
 private function removePriceGroup()
 {
     $ids = $this->db->fetchCol("SELECT id FROM s_core_pricegroups WHERE description = 'TEST-GROUP'");
     foreach ($ids as $id) {
         $group = $this->entityManager->find('Shopware\\Models\\Price\\Group', $id);
         $this->entityManager->remove($group);
         $this->entityManager->flush();
         $this->entityManager->clear();
     }
 }
Esempio n. 6
0
 public function sGetSimilarArticles($articleId = null, $limit = null)
 {
     $limit = empty($limit) ? 6 : (int) $limit;
     $articleId = empty($articleId) ? (int) $this->sSYSTEM->_GET['sArticle'] : (int) $articleId;
     $sql = "\n            SELECT\n              a.id as articleID,\n              a.name as articleName,\n              IF(s.id, 2, 0) + -- Similar article\n              IF(s2.id, 1, 0)  -- Same category\n                as relevance\n\n            FROM s_articles a\n\n            INNER JOIN s_articles_categories_ro ac\n                ON ac.articleID=a.id\n                AND ac.categoryID = {$this->categoryId}\n            INNER JOIN s_categories c\n                ON c.id = ac.categoryID\n                AND c.active = 1\n\n            LEFT JOIN s_articles_avoid_customergroups ag\n            ON ag.articleID=a.id\n            AND ag.customergroupID={$this->customerGroupId}\n\n            LEFT JOIN s_articles o\n            ON o.id={$articleId}\n\n            LEFT JOIN s_articles_similar s\n            ON s.articleID=o.id\n            AND s.relatedarticle=a.id\n\n            LEFT JOIN s_articles_categories_ro s1\n            ON s1.articleID=o.id\n\n            LEFT JOIN s_articles_categories_ro s2\n            ON s2.categoryID=s1.categoryID\n            AND s2.articleID=a.id\n\n            WHERE a.active = 1\n            AND ag.articleID IS NULL\n            AND a.id!={$articleId}\n\n            GROUP BY a.id\n            ORDER BY relevance DESC\n            LIMIT {$limit}\n        ";
     $similarArticleIds = $this->db->fetchCol($sql);
     $similarArticles = array();
     if (!empty($similarArticleIds)) {
         foreach ($similarArticleIds as $similarArticleId) {
             $article = $this->sSYSTEM->sMODULES['sArticles']->sGetPromotionById("fix", 0, (int) $similarArticleId);
             if (!empty($article)) {
                 $similarArticles[] = $article;
             }
         }
     }
     return $similarArticles;
 }
 /**
  * @param Option[] $options
  * @param $imageData
  * @param $parent Image
  */
 protected function createImagesForOptions($options, $imageData, $parent)
 {
     $articleId = $parent->getArticle()->getId();
     $imageData['path'] = null;
     $imageData['parent'] = $parent;
     $join = '';
     foreach ($options as $option) {
         $alias = 'alias' . $option->getId();
         $join = $join . ' INNER JOIN s_article_configurator_option_relations alias' . $option->getId() . ' ON ' . $alias . '.option_id = ' . $option->getId() . ' AND ' . $alias . '.article_id = d.id ';
     }
     $sql = "SELECT d.id\n                FROM s_articles_details d\n        " . $join . "\n        WHERE d.articleID = " . (int) $articleId;
     $details = $this->db->fetchCol($sql);
     foreach ($details as $detailId) {
         $detail = $this->manager->getReference(Detail::class, $detailId);
         $image = new Image();
         $image->fromArray($imageData);
         $image->setArticleDetail($detail);
         $this->manager->persist($image);
     }
 }
 /**
  * Checks whether a category with the given name exists and returns its id.
  * Creates a category if it does not exist and returns the new inserted id.
  *
  * @param $description - category name
  * @param $id - parent id
  * @param $path - category path
  *
  * @return int|string - categoryId
  * @throws AdapterException
  */
 protected function getId($description, $id, $path)
 {
     if ($id === null) {
         $sql = "SELECT id FROM s_categories WHERE description = ? AND path IS NULL";
         $params = [$description];
     } else {
         $sql = "SELECT id FROM s_categories WHERE description = ? AND parent = ?";
         $params = [$description, $id];
     }
     $parentId = $this->db->fetchOne($sql, $params);
     //check whether we have more than one category on the same level with the same name
     $count = $this->db->fetchCol($sql, $params);
     if (count($count) > 1) {
         $message = SnippetsHelper::getNamespace()->get('adapters/articles/category_duplicated', "Category with name '%s' is duplicated");
         throw new AdapterException(sprintf($message, $description));
     }
     //check whether the category should be created
     if (!is_numeric($parentId)) {
         $parentId = $this->insertCategory($description, $id, $path);
         $this->insertCategoryAttributes($parentId);
     }
     return $parentId;
 }
Esempio n. 9
0
 /**
  * get all Käuferschutz article.
  * @return array
  */
 private function getTSArticleNumbers()
 {
     $sql = "SELECT details.ordernumber\n                FROM `s_articles_details` AS details\n                INNER JOIN `s_articles_attributes` AS attributes\n                  ON attributes.articledetailsID = details.id\n                INNER JOIN `s_articles` AS article\n                  ON article.id = details.articleID\n                WHERE ordernumber LIKE 'TS%'\n                  AND attributes.swag_is_trusted_shops_article = 1\n                  AND article.name = 'Käuferschutz'";
     return $this->db->fetchCol($sql);
 }