/** * Helper function for sLogin * Called when provided user data is correct * Logs in the user * * @param $getUser * @param $email * @param $password * @param $isPreHashed * @param $encoderName * @param $plaintext * @param $hash */ private function loginUser($getUser, $email, $password, $isPreHashed, $encoderName, $plaintext, $hash) { $this->regenerateSessionId(); $this->db->update('s_user', array('lastlogin' => new Zend_Date(), 'failedlogins' => 0, 'lockeduntil' => null, 'sessionID' => $this->session->offsetGet('sessionId')), array('id = ?' => $getUser["id"])); $this->eventManager->notify('Shopware_Modules_Admin_Login_Successful', array('subject' => $this, 'email' => $email, 'password' => $password, 'user' => $getUser)); $newHash = ''; $liveMigration = $this->config->offsetGet('liveMigration'); $defaultEncoderName = $this->passwordEncoder->getDefaultPasswordEncoderName(); // Do not allow live migration when the password is prehashed if ($liveMigration && !$isPreHashed && $encoderName !== $defaultEncoderName) { $newHash = $this->passwordEncoder->encodePassword($plaintext, $defaultEncoderName); $encoderName = $defaultEncoderName; } if (empty($newHash)) { $newHash = $this->passwordEncoder->reencodePassword($plaintext, $hash, $encoderName); } if (!empty($newHash) && $newHash !== $hash) { $hash = $newHash; $userId = (int) $getUser['id']; $this->db->update('s_user', array('password' => $hash, 'encoder' => $encoderName), 'id = ' . $userId); } $this->session->offsetSet('sUserMail', $email); $this->session->offsetSet('sUserPassword', $hash); $this->session->offsetSet('sUserId', $getUser["id"]); $this->sCheckUser(); }
/** * Insert articles in comparision chart * @param int $articleId s_articles.id * @throws Enlight_Exception * @return bool true/false */ public function sAddComparison($articleId) { $articleId = (int) $articleId; if (!$articleId) { return null; } // Check if this article is already noted $checkForArticle = $this->db->fetchRow("SELECT id FROM s_order_comparisons WHERE sessionID=? AND articleID=?", [$this->session->offsetGet('sessionId'), $articleId]); // Check if max. numbers of articles for one comparison-session is reached $checkNumberArticles = $this->db->fetchRow("SELECT COUNT(id) AS countArticles FROM s_order_comparisons WHERE sessionID=?", [$this->session->offsetGet('sessionId')]); if ($checkNumberArticles["countArticles"] >= $this->config->offsetGet("sMAXCOMPARISONS")) { return "max_reached"; } if (!$checkForArticle["id"]) { $articleName = $this->db->fetchOne("SELECT s_articles.name AS articleName FROM s_articles WHERE id = ?", [$articleId]); if (!$articleName) { return false; } $sql = "\n INSERT INTO s_order_comparisons (sessionID, userID, articlename, articleID, datum)\n VALUES (?,?,?,?,now())\n "; $queryNewPrice = $this->db->executeUpdate($sql, [$this->session->offsetGet('sessionId'), empty($this->session["sUserId"]) ? 0 : $this->session["sUserId"], $articleName, $articleId]); if (!$queryNewPrice) { throw new Enlight_Exception("sArticles##sAddComparison##01: Error in SQL-query"); } } return true; }
public function sCreateSql() { $sql_add_join = array(); $sql_add_select = array(); $sql_add_where = array(); $skipBackend = $this->shop->get('skipbackend'); $isoCode = $this->shop->get('isocode'); if (empty($skipBackend) && !empty($isoCode)) { $sql_isocode = $this->db->quote($isoCode); $sql_add_join[] = "\n LEFT JOIN s_core_translations as ta\n ON ta.objectkey=a.id AND ta.objecttype='article' AND ta.objectlanguage={$sql_isocode}\n\n LEFT JOIN s_core_translations as td\n ON td.objectkey=d.id AND td.objecttype='variant' AND td.objectlanguage={$sql_isocode}\n "; $sql_add_select[] = "ta.objectdata as article_translation"; $sql_add_select[] = "td.objectdata as detail_translation"; //read the fallback for the case the translation is not going to be set $fallbackId = $this->shop->getFallback() ? $this->shop->getFallback()->getId() : null; if (!empty($fallbackId)) { $sqlFallbackLanguageId = $this->db->quote($fallbackId); $sql_add_join[] = "\n LEFT JOIN s_core_translations as taf\n ON taf.objectkey=a.id AND taf.objecttype='article' AND taf.objectlanguage={$sqlFallbackLanguageId}\n\n LEFT JOIN s_core_translations as tdf\n ON tdf.objectkey=d.id AND tdf.objecttype='variant' AND tdf.objectlanguage={$sqlFallbackLanguageId}\n "; $sql_add_select[] = "taf.objectdata as article_translation_fallback"; $sql_add_select[] = "tdf.objectdata as detail_translation_fallback"; } } if (!empty($this->sSettings["categoryID"])) { $sql_add_join[] = "\n INNER JOIN s_articles_categories_ro act\n ON act.articleID = a.id\n AND act.categoryID = {$this->sSettings["categoryID"]}\n INNER JOIN s_categories c\n ON c.id = act.categoryID\n AND c.active = 1\n "; } if (empty($this->sSettings["image_filter"])) { $sql_add_join[] = "\n LEFT JOIN s_articles_img as i\n ON i.articleID = a.id AND i.main=1 AND i.article_detail_id IS NULL\n "; } else { $sql_add_join[] = "\n JOIN s_articles_img as i\n ON i.articleID = a.id AND i.main=1 AND i.article_detail_id IS NULL\n "; } if (!empty($this->sCustomergroup["groupkey"]) && empty($this->sCustomergroup["mode"]) && $this->sCustomergroup["groupkey"] != "EK") { $sql_add_join[] = "\n LEFT JOIN s_articles_prices as p2\n ON p2.articledetailsID = d.id AND p2.`from`=1\n AND p2.pricegroup='{$this->sCustomergroup["groupkey"]}'\n AND p2.price!=0\n "; $pricefield = "IFNULL(p2.price, p.price)"; $pseudoprice = "IFNULL(p2.pseudoprice, p.pseudoprice)"; $baseprice = "IFNULL(p2.baseprice, p.baseprice)"; } else { $pricefield = "p.price"; $pseudoprice = "p.pseudoprice"; $baseprice = "p.baseprice"; } if (empty($this->sSettings["variant_export"]) || $this->sSettings["variant_export"] == 1) { $sql_add_select[] = "IF(COUNT(d.ordernumber) <= 1, '', GROUP_CONCAT(DISTINCT(CONCAT('\"', d.id, ':', REPLACE(d.ordernumber,'\"','\"\"'),'\"')) SEPARATOR ';')) as group_ordernumber"; $sql_add_select[] = "IF(COUNT(d.additionaltext) <= 1, '', GROUP_CONCAT(DISTINCT(CONCAT('\"', d.id, ':', REPLACE(d.additionaltext,'\"','\"\"'),'\"')) SEPARATOR ';')) as group_additionaltext"; $sql_add_select[] = "IF(COUNT({$pricefield})<=1,'',GROUP_CONCAT(ROUND(CAST({$pricefield}*(100-IF(pd.discount,pd.discount,0)-{$this->sCustomergroup["discount"]})/100*{$this->sCurrency["factor"]} AS DECIMAL(10,3)),2) SEPARATOR ';')) as group_pricenet"; $sql_add_select[] = "IF(COUNT({$pricefield})<=1,'',GROUP_CONCAT(ROUND(CAST({$pricefield}*(100+t.tax-IF(pd.discount,pd.discount,0)-{$this->sCustomergroup["discount"]})/100*{$this->sCurrency["factor"]} AS DECIMAL(10,3)),2) SEPARATOR ';')) as group_price"; $sql_add_select[] = "IF(COUNT(d.active)<=1,'',GROUP_CONCAT(d.active SEPARATOR ';')) as group_active"; $sql_add_select[] = "IF(COUNT(d.instock)<=1,'',GROUP_CONCAT(d.instock SEPARATOR ';')) as group_instock"; $sql_add_group_by = "a.id"; $sql_add_article_detail_join_condition = "AND d.kind=1"; } elseif ($this->sSettings["variant_export"] == 2) { $sql_add_group_by = "d.id"; $sql_add_article_detail_join_condition = ''; } $grouppricefield = "gp.price"; if (empty($this->sSettings["variant_export"]) || $this->sSettings["variant_export"] == 2 || $this->sSettings["variant_export"] == 1) { $sql_add_join[] = "\n JOIN (SELECT NULL as `articleID` , NULL as `valueID` , NULL as `attr1` , NULL as `attr2` , NULL as `attr3` , NULL as `attr4` , NULL as `attr5` , NULL as `attr6` , NULL as `attr7` , NULL as `attr8` , NULL as `attr9` , NULL as `attr10` , NULL as `standard` , NULL as `active` , NULL as `ordernumber` , NULL as `instock`, NULL as `minpurchase`) as v\n "; $sql_add_join[] = "\n JOIN (SELECT NULL as articleID, NULL as valueID, NULL as groupkey, NULL as price, NULL as optionID) as gp\n "; } if (!empty($this->sSettings["active_filter"])) { $sql_add_where[] = "(a.active = 1 AND (v.active=1 OR (v.active IS NULL AND d.active=1)))"; } if (!empty($this->sSettings["stockmin_filter"])) { $sql_add_where[] = "(v.instock>=d.stockmin OR (v.instock IS NULL AND d.instock>=d.stockmin))"; } if (!empty($this->sSettings["instock_filter"])) { $sql_add_where[] = "(v.instock>={$this->sSettings["instock_filter"]} OR (v.instock IS NULL AND d.instock>={$this->sSettings["instock_filter"]}))"; } if (!empty($this->sSettings["price_filter"])) { $sql_add_where[] = "ROUND(CAST(IFNULL({$grouppricefield},{$pricefield})*(100+t.tax-IF(pd.discount IS NULL,0,pd.discount)-{$this->sCustomergroup["discount"]})/100*{$this->sCurrency["factor"]} AS DECIMAL(10,3)),2)>=" . $this->sSettings["price_filter"]; } if (!empty($this->sSettings["own_filter"]) && trim($this->sSettings["own_filter"])) { $sql_add_where[] = "(" . $this->sSettings["own_filter"] . ")"; } if ($this->config->offsetGet('hideNoInstock')) { $sql_add_where[] = "(\n (a.laststock * v.instock >= a.laststock * v.minpurchase)\n OR\n (a.laststock * d.instock >= a.laststock * d.minpurchase)\n )"; } $sql_add_join = implode(" ", $sql_add_join); if (!empty($sql_add_select)) { $sql_add_select = ", " . implode(", ", $sql_add_select); } else { $sql_add_select = ""; } if (!empty($sql_add_where)) { $sql_add_where = " AND " . implode(" AND ", $sql_add_where); } else { $sql_add_where = ""; } if (!empty($sql_add_group_by)) { $sql_add_group_by = "GROUP BY ({$sql_add_group_by})"; } else { $sql_add_group_by = ""; } $sql = "\n SELECT\n a.id as `articleID`,\n a.name,\n a.description,\n a.description_long,\n a.main_detail_id,\n d.shippingtime,\n d.shippingfree,\n a.topseller,\n a.keywords,\n d.minpurchase,\n d.purchasesteps,\n d.maxpurchase,\n d.purchaseunit,\n d.referenceunit,\n a.taxID,\n a.filtergroupID,\n a.supplierID,\n d.unitID,\n IF(a.changetime!='0000-00-00 00:00:00',a.changetime,'') as `changed`,\n IF(a.datum!='0000-00-00',a.datum,'') as `added`,\n IF(d.releasedate!='0000-00-00',d.releasedate,'') as `releasedate`,\n a.active as active,\n\n d.id as `articledetailsID`,\n IF(v.ordernumber IS NOT NULL,v.ordernumber,d.ordernumber) as ordernumber,\n\n d.suppliernumber,\n d.ean,\n d.width,\n d.height,\n d.length,\n d.kind,\n IF(v.standard=1||kind=1,1,0) as standard,\n d.additionaltext,\n COALESCE(sai.impressions, 0) as impressions,\n d.sales,\n\n IF(v.active IS NOT NULL,IF(a.active=0,0,v.active),a.active) as active,\n IF(v.instock IS NOT NULL,v.instock,d.instock) as instock,\n (\n SELECT AVG(av.points)\n FROM s_articles_vote as av WHERE active=1\n AND articleID=a.id\n ) as sVoteAverage,\n (\n SELECT COUNT(*)\n FROM s_articles_vote as av WHERE active=1\n AND articleID=a.id\n ) as sVoteCount,\n d.stockmin,\n d.weight,\n d.position,\n\n at.attr1, at.attr2, at.attr3, at.attr4, at.attr5, at.attr6, at.attr7, at.attr8, at.attr9, at.attr10,\n at.attr11, at.attr12, at.attr13, at.attr14, at.attr15, at.attr16, at.attr17, at.attr18, at.attr19, at.attr20,\n\n s.name as supplier,\n u.unit,\n u.description as unit_description,\n t.tax,\n CONCAT(i.img, '.', i.extension) as image,\n\n a.configurator_set_id as configurator,\n\n ROUND(CAST(IFNULL({$grouppricefield}, {$pricefield})*(100-IF(pd.discount,pd.discount,0)-{$this->sCustomergroup["discount"]})/100*{$this->sCurrency["factor"]} AS DECIMAL(10,3)),2) as netprice,\n ROUND(CAST(IFNULL({$grouppricefield}, {$pricefield})*(100+t.tax)/100*(100-IF(pd.discount,pd.discount,0)-{$this->sCustomergroup["discount"]})/100*{$this->sCurrency["factor"]} AS DECIMAL(10,3)),2) as price,\n pd.discount,\n ROUND(CAST({$pseudoprice}*{$this->sCurrency["factor"]} AS DECIMAL(10,3)),2) as netpseudoprice,\n ROUND(CAST({$pseudoprice}*(100+t.tax)*{$this->sCurrency["factor"]}/100 AS DECIMAL(10,3)),2) as pseudoprice,\n {$baseprice},\n IF(file IS NULL,0,1) as esd\n\n {$sql_add_select}\n\n FROM s_articles a\n INNER JOIN s_articles_details d\n ON d.articleID = a.id\n {$sql_add_article_detail_join_condition}\n LEFT JOIN s_articles_attributes at\n ON d.id = at.articledetailsID\n\n LEFT JOIN `s_core_units` as `u`\n ON d.unitID = u.id\n LEFT JOIN `s_core_tax` as `t`\n ON a.taxID = t.id\n LEFT JOIN `s_articles_supplier` as `s`\n ON a.supplierID = s.id\n\n LEFT JOIN s_core_pricegroups_discounts pd\n ON a.pricegroupActive=1\n AND\ta.pricegroupID=groupID\n AND customergroupID = 1\n AND discountstart=1\n\n LEFT JOIN s_articles_esd e ON e.articledetailsID=d.id\n\n LEFT JOIN (\n SELECT articleID\n FROM\n s_export_categories as ec,\n s_articles_categories_ro as ac\n WHERE feedID={$this->sFeedID}\n AND ec.categoryID=ac.categoryID\n GROUP BY articleID\n ) AS bc\n ON bc.articleID=a.id\n\n LEFT JOIN s_export_suppliers AS bs\n ON (bs.supplierID=s.id AND bs.feedID={$this->sFeedID})\n\n LEFT JOIN s_export_articles AS ba\n ON (ba.articleID=a.id AND ba.feedID={$this->sFeedID})\n\n LEFT JOIN s_articles_prices AS p\n ON p.articledetailsID = d.id\n AND p.`from`=1\n AND p.pricegroup='EK'\n\n LEFT JOIN\n (\n SELECT articleId AS id, SUM(s.impressions) AS impressions\n FROM s_statistics_article_impression s\n GROUP BY articleId\n ) sai ON sai.id = a.id\n\n {$sql_add_join}\n\n WHERE bc.articleID IS NULL\n AND bs.supplierID IS NULL\n AND a.mode = 0\n AND d.kind != 3\n AND ba.articleID IS NULL\n {$sql_add_where}\n\n {$sql_add_group_by}\n "; if (!empty($this->sSettings["count_filter"])) { $sql .= "LIMIT " . $this->sSettings["count_filter"]; } return $sql; }
/** * @covers sBasket::sAddVoucher */ public function testsAddVoucherWithAbsoluteVoucher() { // Test with empty args and session, expect failure $result = $this->module->sAddVoucher(''); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertTrue($result['sErrorFlag']); $this->assertContains($this->snippetManager->getNamespace('frontend/basket/internalMessages')->get('VoucherFailureNotFound', 'Voucher could not be found or is not valid anymore'), $result['sErrorMessages']); // Create session id and try again, same results $this->module->sSYSTEM->sSESSION_ID = uniqid(); $this->session->offsetSet('sessionId', $this->module->sSYSTEM->sSESSION_ID); $result = $this->module->sAddVoucher(''); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertTrue($result['sErrorFlag']); $this->assertContains($this->snippetManager->getNamespace('frontend/basket/internalMessages')->get('VoucherFailureNotFound', 'Voucher could not be found or is not valid anymore'), $result['sErrorMessages']); $voucherData = array('vouchercode' => 'testOne', 'description' => 'testOne description', 'numberofunits' => 1, 'value' => 10, 'minimumcharge' => 10, 'ordercode' => uniqid(), 'modus' => 0); // Try with valid voucher code, empty basket $this->db->insert('s_emarketing_vouchers', $voucherData); $this->module->sSYSTEM->sSESSION_ID = uniqid(); $this->session->offsetSet('sessionId', $this->module->sSYSTEM->sSESSION_ID); $result = $this->module->sAddVoucher('testOne'); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertTrue($result['sErrorFlag']); $this->assertContains(str_replace("{sMinimumCharge}", $voucherData["minimumcharge"], $this->snippetManager->getNamespace('frontend/basket/internalMessages')->get('VoucherFailureMinimumCharge', 'The minimum charge for this voucher is {sMinimumCharge}')), $result['sErrorMessages']); // Add one article to the basket with enough value to use discount $randomArticle = $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'); $this->db->insert('s_order_basket', array('price' => $voucherData["minimumcharge"] + 1, 'quantity' => 1, 'sessionID' => $this->session->get('sessionId'), 'ordernumber' => $randomArticle['ordernumber'], 'articleID' => $randomArticle['articleID'])); // Add voucher to the orders table, so we can test the usage limit $this->db->insert('s_order_details', array('articleordernumber' => $voucherData['ordercode'])); $result = $this->module->sAddVoucher('testOne'); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertTrue($result['sErrorFlag']); $this->assertContains($this->snippetManager->getNamespace('frontend/basket/internalMessages')->get('VoucherFailureNotFound', 'Voucher could not be found or is not valid anymore'), $result['sErrorMessages']); $this->db->delete('s_order_details', array('articleordernumber = ?' => $voucherData['ordercode'])); $previousAmount = $this->module->sGetAmount(); // Voucher should work ok now $this->assertTrue($this->module->sAddVoucher('testOne')); $this->assertLessThan($previousAmount, $this->module->sGetAmount()); // Test the voucher values with tax from user group $discount = $this->db->fetchRow('SELECT * FROM s_order_basket WHERE modus = 2 and sessionID = ?', array($this->module->sSYSTEM->sSESSION_ID)); $this->assertEquals($voucherData['value'] * -1, $discount['price']); $this->assertEquals($this->config->offsetGet('sVOUCHERTAX'), $discount['tax_rate']); $this->assertEquals($voucherData['value'] * -1, round($discount['netprice'] * (100 + $discount['tax_rate']) / 100)); // Second voucher should fail $result = $this->module->sAddVoucher('testOne'); $this->assertInternalType('array', $result); $this->assertArrayHasKey('sErrorFlag', $result); $this->assertArrayHasKey('sErrorMessages', $result); $this->assertTrue($result['sErrorFlag']); $this->assertContains($this->snippetManager->getNamespace('frontend/basket/internalMessages')->get('VoucherFailureOnlyOnes', 'Only one voucher can be processed in order'), $result['sErrorMessages']); // Housekeeping $this->db->delete('s_order_basket', array('sessionID = ?' => $this->session->get('sessionId'))); $this->db->delete('s_emarketing_vouchers', array('vouchercode = ?' => 'testOne')); }