/** * Add voucher to cart * * At failure view variable sVoucherError will give further information * At success return to cart / confirm view */ public function addVoucherAction() { if ($this->Request()->isPost()) { $voucher = $this->basket->sAddVoucher($this->Request()->getParam('sVoucher')); if (!empty($voucher['sErrorMessages'])) { $this->View()->sVoucherError = $voucher['sErrorMessages']; } } $this->forward($this->Request()->getParam('sTargetAction', 'index')); }
/** * @covers sBasket::sAddVoucher */ public function testsAddVoucherWithSupplier() { $randomArticleOne = $this->db->fetchRow('SELECT * FROM s_articles_details detail INNER JOIN s_articles article ON article.id = detail.articleID WHERE detail.active = 1 ORDER BY RAND() LIMIT 1'); $randomArticleTwo = $this->db->fetchRow('SELECT * FROM s_articles_details detail INNER JOIN s_articles article ON article.id = detail.articleID WHERE detail.active = 1 AND supplierID <> ? ORDER BY RAND() LIMIT 1', array($randomArticleOne['supplierID'])); $voucherData = array('vouchercode' => 'testOne', 'description' => 'testOne description', 'numberofunits' => 1, 'numorder' => 1, 'value' => 10, 'minimumcharge' => 10, 'ordercode' => uniqid(), 'modus' => 0, 'bindtosupplier' => $randomArticleOne['supplierID']); // Try with valid voucher code, empty basket $this->db->insert('s_emarketing_vouchers', $voucherData); $customer = $this->createDummyCustomer(); $this->session['sUserId'] = $customer->getId(); $this->module->sSYSTEM->sSESSION_ID = uniqid(); $this->session->offsetSet('sessionId', $this->module->sSYSTEM->sSESSION_ID); // Add first article to the basket with enough value to use discount, should fail $this->db->insert('s_order_basket', array('price' => $voucherData["minimumcharge"] + 1, 'quantity' => 1, 'sessionID' => $this->session->get('sessionId'), 'ordernumber' => $randomArticleTwo['ordernumber'], 'articleID' => $randomArticleTwo['articleID'])); $supplierOne = $this->db->fetchOne('SELECT name FROM s_articles_supplier WHERE id = ?', array($randomArticleOne['supplierID'])); $result = $this->module->sAddVoucher($voucherData['vouchercode']); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertTrue($result['sErrorFlag']); $this->assertContains(str_replace("{sSupplier}", $supplierOne, $this->snippetManager->getNamespace('frontend/basket/internalMessages')->get('VoucherFailureSupplier', 'This voucher is only available for products from {sSupplier}')), $result['sErrorMessages']); $this->db->insert('s_order_basket', array('price' => $voucherData["minimumcharge"] + 1, 'quantity' => 1, 'sessionID' => $this->session->get('sessionId'), 'ordernumber' => $randomArticleOne['ordernumber'], 'articleID' => $randomArticleOne['articleID'])); $previousAmount = $this->module->sGetAmount(); // Test with one-time code, success $this->assertTrue($this->module->sAddVoucher($voucherData['vouchercode'])); $this->assertLessThan($previousAmount, $this->module->sGetAmount()); // Housekeeping $this->db->delete('s_order_basket', array('sessionID = ?' => $this->session->get('sessionId'))); $this->db->delete('s_emarketing_vouchers', array('vouchercode = ?' => $voucherData['vouchercode'])); $this->deleteDummyCustomer($customer); }