/** * @covers sBasket::sGetBasketIds */ public function testsGetBasketIds() { $randomArticles = $this->db->fetchAll('SELECT * FROM s_articles_details detail INNER JOIN s_articles article ON article.id = detail.articleID WHERE detail.active = 1 ORDER BY RAND() LIMIT 2'); $this->module->sSYSTEM->sSESSION_ID = uniqid(); $this->session->offsetSet('sessionId', $this->module->sSYSTEM->sSESSION_ID); // Test with empty basket, empty $this->assertNull($this->module->sGetBasketIds()); // Add the first article to the basket, test we get the article id $this->db->insert('s_order_basket', array('price' => 1, 'quantity' => 1, 'sessionID' => $this->session->get('sessionId'), 'ordernumber' => $randomArticles[0]['ordernumber'], 'articleID' => $randomArticles[0]['articleID'])); $this->assertEquals(array($randomArticles[0]['articleID']), $this->module->sGetBasketIds()); // Add the first article to the basket again, test we get the same result $this->db->insert('s_order_basket', array('price' => 1, 'quantity' => 1, 'sessionID' => $this->session->get('sessionId'), 'ordernumber' => $randomArticles[0]['ordernumber'], 'articleID' => $randomArticles[0]['articleID'])); $this->assertEquals(array($randomArticles[0]['articleID']), $this->module->sGetBasketIds()); // Add the second article to the basket, test we get the two ids $this->db->insert('s_order_basket', array('price' => 1, 'quantity' => 1, 'sessionID' => $this->session->get('sessionId'), 'ordernumber' => $randomArticles[1]['ordernumber'], 'articleID' => $randomArticles[1]['articleID'])); $basketIds = $this->module->sGetBasketIds(); $this->assertContains($randomArticles[0]['articleID'], $basketIds); $this->assertContains($randomArticles[1]['articleID'], $basketIds); // Housekeeping $this->db->delete('s_order_basket', array('sessionID = ?' => $this->session->get('sessionId'))); }
/** * Get articles that bought in combination with last added product to * display on cart page * * @param int $articleID * @return array */ public function getBoughtToo($articleID) { Shopware()->Modules()->Marketing()->sBlacklist = $this->basket->sGetBasketIds(); $alsoBoughtId = Shopware()->Modules()->Marketing()->sGetAlsoBoughtArticles($articleID); $alsoBoughts = array(); if (!empty($alsoBoughtId)) { foreach ($alsoBoughtId as $alsoBoughtItem) { $temp = Shopware()->Modules()->Articles()->sGetPromotionById('fix', 0, (int) $alsoBoughtItem['id']); if (!empty($temp)) { $alsoBoughts[] = $temp; } } } return $alsoBoughts; }