/** * @covers sAdmin::sGetPremiumShippingcosts */ public function testsGetPremiumShippingcosts() { // No basket, return false, $this->assertFalse($this->module->sGetPremiumShippingcosts()); $countries = $this->module->sGetCountryList(); foreach ($countries as $country) { if ($country['countryiso']) { $germany = $country; break; } } $this->module->sSYSTEM->sSESSION_ID = uniqid(); $this->session->offsetSet('sessionId', $this->module->sSYSTEM->sSESSION_ID); $this->basketModule->sAddArticle('SW10010'); // With country data, no dispatch method $this->assertEquals(array('brutto' => 0, 'netto' => 0), $this->module->sGetPremiumShippingcosts($germany)); // With dispatch method $this->session->offsetSet('sDispatch', 9); $result = $this->module->sGetPremiumShippingcosts($germany); $this->assertArrayHasKey('brutto', $result); $this->assertArrayHasKey('netto', $result); $this->assertArrayHasKey('value', $result); $this->assertArrayHasKey('factor', $result); $this->assertArrayHasKey('surcharge', $result); $this->assertArrayHasKey('tax', $result); }
/** * Add more then one article directly from cart / confirm view * @param sAddAccessories = List of article ordernumbers separated by ; * @param sAddAccessoriesQuantity = List of article quantities separated by ; */ public function addAccessoriesAction() { $accessories = $this->Request()->getParam('sAddAccessories'); $accessoriesQuantity = $this->Request()->getParam('sAddAccessoriesQuantity'); if(is_string($accessories)) { $accessories = explode(';', $accessories); } if(!empty($accessories)&&is_array($accessories)) { foreach ($accessories as $key => $accessory) { try { if (!empty($accessoriesQuantity[$key])){ $quantity = intval($accessoriesQuantity[$key]); }else { $quantity = 1; } $this->basket->sAddArticle($accessory, $quantity); } catch (Exception $e) { } } } $this->forward($this->Request()->getParam('sTargetAction', 'index')); }
/** * @param string|array $accessories * @param array $quantities */ private function addAccessories($accessories, $quantities) { if (is_string($accessories)) { $accessories = explode(';', $accessories); } if (empty($accessories) || !is_array($accessories)) { return; } foreach ($accessories as $key => $accessory) { try { $quantity = 1; if (!empty($quantities[$key])) { $quantity = intval($quantities[$key]); } $this->basket->sAddArticle($accessory, $quantity); } catch (Exception $e) { } } }
/** * @covers sBasket::sAddArticle */ public function testsAddArticle() { // No id, expect false $this->assertFalse($this->module->sAddArticle(null)); $this->module->sSYSTEM->sSESSION_ID = uniqid(); $this->session->offsetSet('sessionId', $this->module->sSYSTEM->sSESSION_ID); // Get random article with stock controll and add it to the basket $randomArticleOne = $this->db->fetchRow('SELECT detail.* FROM s_articles_details detail INNER JOIN s_articles article ON article.id = detail.articleID LEFT JOIN s_articles_avoid_customergroups avoid ON avoid.articleID = article.id WHERE detail.active = 1 AND laststock = 1 AND instock > 3 AND avoid.articleID IS NULL AND article.id NOT IN ( SELECT articleID FROM s_articles_avoid_customergroups WHERE customergroupID = 1 ) ORDER BY RAND() LIMIT 1'); // Adding article without quantity adds one $this->module->sAddArticle($randomArticleOne['ordernumber']); $basket = $this->module->sGetBasket(); $this->assertEquals(1, $basket['Quantity']); $this->assertEquals(1, $basket['content'][0]['quantity']); // Adding article with quantity adds correctly, finds stacks $this->module->sAddArticle($randomArticleOne['ordernumber'], 2); $basket = $this->module->sGetBasket(); $this->assertEquals(1, $basket['Quantity']); $this->assertEquals(3, $basket['content'][0]['quantity']); // Start over $this->module->sDeleteBasket(); // Adding article with quantity over stock, check that we have the available stock $this->module->sAddArticle($randomArticleOne['ordernumber'], $randomArticleOne['instock'] + 200); $basket = $this->module->sGetBasket(); $this->assertEquals(1, $basket['Quantity']); $this->assertEquals(min($randomArticleOne['instock'], 100), $basket['content'][0]['quantity']); // Start over $this->module->sDeleteBasket(); // Get random article and add it to the basket $randomArticleTwo = $this->db->fetchRow('SELECT detail.* FROM s_articles_details detail INNER JOIN s_articles article ON article.id = detail.articleID WHERE detail.active = 1 AND laststock = 0 AND instock > 20 AND instock < 70 AND article.id NOT IN ( SELECT articleID FROM s_articles_avoid_customergroups WHERE customergroupID = 1 ) ORDER BY RAND() LIMIT 1'); // Adding article with quantity over stock, check that we have the desired quantity $this->module->sAddArticle($randomArticleTwo['ordernumber'], $randomArticleTwo['instock'] + 20); $basket = $this->module->sGetBasket(); $this->assertEquals(1, $basket['Quantity']); $this->assertEquals(min($randomArticleTwo['instock'] + 20, 100), $basket['content'][0]['quantity']); // Housekeeping $this->db->delete('s_order_basket', array('sessionID = ?' => $this->session->get('sessionId'))); }