/** * Read a specific, static page (E.g. terms and conditions, etc.) * * @param int $staticId The page id * @param int $shopId Id of the shop * @return array|false Page data, or false if none found by given id */ public function sGetStaticPage($staticId = null, $shopId = null) { if (empty($staticId)) { $staticId = (int) $this->front->Request()->getQuery('sCustom', $staticId); } if (empty($staticId)) { return false; } $sql = "SELECT * FROM s_cms_static WHERE id = :pageId"; $params = array('pageId' => $staticId); if ($shopId) { $sql .= ' AND (shop_ids IS NULL OR shop_ids LIKE :shopId)'; $params['shopId'] = '%|' . $shopId . '|%'; } // Load static page data from database $staticPage = $this->db->fetchRow($sql, $params); if ($staticPage === false) { return false; } /** * Add support for sub pages */ if (!empty($staticPage['parentID'])) { $staticPage = $this->getRelatedForSubPage($staticPage, $shopId); } else { $staticPage = $this->getRelatedForPage($staticPage, $shopId); } return $staticPage; }
/** * @covers sAdmin::sNewsletterSubscription */ public function testsNewsletterSubscriptionWithPostData() { // Test subscribe with empty post field and empty address, fail validation $this->front->Request()->setPost('newsletter', ''); $result = $this->module->sNewsletterSubscription(''); $this->assertEquals(array('code' => 5, 'message' => $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('ErrorFillIn', 'Please fill in all red fields'), 'sErrorFlag' => array('newsletter' => true)), $result); }
/** * Private helper method for sValidateStep1 * Validates email data * * @param $edit * @param $postData * @param $sErrorMessages * @param $sErrorFlag * @return array Error data */ private function validateStep1Email($edit, &$postData, &$sErrorMessages, &$sErrorFlag) { // Email is present in post data if (isset($postData["emailConfirmation"]) || isset($postData["email"])) { $postData["email"] = strtolower(trim($postData["email"])); if (empty($postData["email"]) || !$this->emailValidator->isValid($postData["email"])) { $sErrorFlag["email"] = true; $sErrorMessages[] = $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('MailFailure', 'Please enter a valid mail address'); } // Check email confirmation if needed if (isset($postData["emailConfirmation"])) { $postData["emailConfirmation"] = strtolower(trim($postData["emailConfirmation"])); if ($postData["email"] != $postData["emailConfirmation"]) { $sErrorFlag["emailConfirmation"] = true; $sErrorMessages[] = $this->snippetManager->getNamespace('frontend/account/internalMessages')->get('MailFailureNotEqual', 'The mail addresses entered are not equal'); } } } elseif ($edit && empty($postData["email"])) { $userEmail = $this->session->offsetGet('sUserMail'); if ($userEmail) { $this->front->Request()->setPost('email', $userEmail); } $postData["email"] = $userEmail; } }
/** * Read a specific, static page (E.g. terms and conditions, etc.) * * @param int $staticId The page id * @return array|false Page data, or false if none found by given id */ public function sGetStaticPage($staticId = null) { if (empty($staticId)) { $staticId = (int) $this->front->Request()->getQuery('sCustom', $staticId); } if (empty($staticId)) { return false; } // Load static page data from database $staticPage = $this->db->fetchRow("SELECT * FROM s_cms_static WHERE id = ?", array($staticId)); if ($staticPage === false) { return false; } /** * Add support for sub pages */ if (!empty($staticPage['parentID'])) { $sql = ' SELECT p.id, p.description, p.link, p.target, IF(p.id=?, 1, 0) as active, p.page_title FROM s_cms_static p WHERE p.parentID = ? ORDER BY p.position '; $staticPage['siblingPages'] = $this->db->fetchAll($sql, array($staticId, $staticPage['parentID'])); $sql = ' SELECT p.id, p.description, p.link, p.target, p.page_title FROM s_cms_static p WHERE p.id = ? '; $staticPage['parent'] = $this->db->fetchRow($sql, array($staticPage['parentID'])); $staticPage['parent'] = $staticPage['parent'] ?: array(); } else { $sql = ' SELECT p.id, p.description, p.link, p.target, p.page_title FROM s_cms_static p WHERE p.parentID = ? ORDER BY p.position '; $staticPage['subPages'] = $this->db->fetchAll($sql, array($staticId)); } return $staticPage; }
/** * Creates query string for an url based on sVariables and Request GET variables * * @param array $sVariables Variables that configure the generated url * @return string */ public function sBuildLink($sVariables) { $url = array(); $allowedCategoryVariables = array("sCategory", "sPage"); $tempGET = $this->front->Request() ? $this->front->Request()->getParams() : null; // If viewport is available, this will be the first variable if (!empty($tempGET["sViewport"])) { $url['sViewport'] = $tempGET["sViewport"]; if ($url["sViewport"] === "cat") { foreach ($allowedCategoryVariables as $allowedVariable) { if (!empty($tempGET[$allowedVariable])) { $url[$allowedVariable] = $tempGET[$allowedVariable]; unset($tempGET[$allowedVariable]); } } $tempGET = array(); } unset($tempGET["sViewport"]); } // Strip new variables from _GET foreach ($sVariables as $getKey => $getValue) { $tempGET[$getKey] = $getValue; } // Strip session from array unset($tempGET['coreID']); unset($tempGET['sPartner']); foreach ($tempGET as $getKey => $getValue) { if ($getValue) { $url[$getKey] = $getValue; } } if (!empty($url)) { $queryString = '?' . http_build_query($url, "", "&"); } else { $queryString = ''; } return $queryString; }
/** * Loads relevant associated data for the provided articles * Used in sGetBasket * * @param $getArticles * @return array */ private function getBasketArticlesUncached($getArticles) { $totalAmount = 0; $discount = 0; $totalAmountWithTax = 0; $totalAmountNet = 0; $totalCount = 0; foreach (array_keys($getArticles) as $key) { $getArticles[$key] = $this->eventManager->filter('Shopware_Modules_Basket_GetBasket_FilterItemStart', $getArticles[$key], array('subject' => $this, 'getArticles' => $getArticles)); $getArticles[$key]["shippinginfo"] = empty($getArticles[$key]["modus"]); if (!empty($getArticles[$key]["releasedate"]) && strtotime($getArticles[$key]["releasedate"]) <= time()) { $getArticles[$key]["sReleaseDate"] = $getArticles[$key]["releasedate"] = ""; } $getArticles[$key]["esd"] = $getArticles[$key]["esdarticle"]; if (empty($getArticles[$key]["minpurchase"])) { $getArticles[$key]["minpurchase"] = 1; } if (empty($getArticles[$key]["purchasesteps"])) { $getArticles[$key]["purchasesteps"] = 1; } if ($getArticles[$key]["purchasesteps"] <= 0) { unset($getArticles[$key]["purchasesteps"]); } if (empty($getArticles[$key]["maxpurchase"])) { $getArticles[$key]["maxpurchase"] = $this->config->get('sMAXPURCHASE'); } if (!empty($getArticles[$key]["laststock"]) && $getArticles[$key]["instock"] < $getArticles[$key]["maxpurchase"]) { $getArticles[$key]["maxpurchase"] = $getArticles[$key]["instock"]; } // Get additional basket meta data for each product if ($getArticles[$key]["modus"] == 0) { $tempArticle = $this->moduleManager->Articles()->sGetProductByOrdernumber($getArticles[$key]['ordernumber']); if (empty($tempArticle)) { $getArticles[$key]["additional_details"] = array("properties" => array()); } else { $getArticles[$key]['additional_details'] = $tempArticle; $properties = ''; if (isset($getArticles[$key]['additional_details']['sProperties'])) { foreach ($getArticles[$key]['additional_details']['sProperties'] as $property) { $properties .= $property['name'] . ': ' . $property['value'] . ', '; } } $getArticles[$key]['additional_details']['properties'] = substr($properties, 0, -7); } } // If unitID is set, query it if (!empty($getArticles[$key]["unitID"])) { $getUnitData = $this->moduleManager->Articles()->sGetUnit($getArticles[$key]["unitID"]); $getArticles[$key]["itemUnit"] = $getUnitData["description"]; } else { unset($getArticles[$key]["unitID"]); } if (!empty($getArticles[$key]["packunit"])) { $getPackUnit = array(); // If we are loading a variant, look for a translation in the variant translation set if ($getArticles[$key]['mainDetailId'] != $getArticles[$key]['articleDetailId']) { $getPackUnit = $this->moduleManager->Articles()->sGetTranslation(array(), $getArticles[$key]["articleDetailId"], "variant", $this->sSYSTEM->sLanguage); } // If we are using the main variant or the variant has no translation // look for translation in the article translation set if ($getArticles[$key]['mainDetailId'] == $getArticles[$key]['articleDetailId'] || empty($getPackUnit["packunit"])) { $getPackUnit = $this->moduleManager->Articles()->sGetTranslation(array(), $getArticles[$key]["articleID"], "article", $this->sSYSTEM->sLanguage); } if (!empty($getPackUnit["packunit"])) { $getArticles[$key]["packunit"] = $getPackUnit["packunit"]; } } $quantity = $getArticles[$key]["quantity"]; $price = $getArticles[$key]["price"]; $netprice = $getArticles[$key]["netprice"]; if ($getArticles[$key]["modus"] == 2) { $ticketResult = $this->db->fetchRow('SELECT vouchercode,taxconfig FROM s_emarketing_vouchers WHERE ordercode = ?', array($getArticles[$key]["ordernumber"])) ?: array(); if (!$ticketResult["vouchercode"]) { // Query Voucher-Code $queryVoucher = $this->db->fetchRow('SELECT code FROM s_emarketing_voucher_codes WHERE id = ? AND cashed != 1', array($getArticles[$key]["articleID"])) ?: array(); $ticketResult["vouchercode"] = $queryVoucher["code"]; } $this->sDeleteArticle($getArticles[$key]["id"]); //if voucher was deleted, do not restore if ($this->front->Request()->getQuery('sDelete') != 'voucher') { $this->sAddVoucher($ticketResult["vouchercode"]); } } $tax = $getArticles[$key]["tax_rate"]; // If shop is in net mode, we have to consider // the tax separately if ($this->config->get('sARTICLESOUTPUTNETTO') && !$this->sSYSTEM->sUSERGROUPDATA["tax"] || !$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"]) { if (empty($getArticles[$key]["modus"])) { $priceWithTax = round($netprice, 2) / 100 * (100 + $tax); $getArticles[$key]["amountWithTax"] = $quantity * $priceWithTax; // If basket comprised any discount, calculate brutto-value for the discount if ($this->sSYSTEM->sUSERGROUPDATA["basketdiscount"] && $this->sCheckForDiscount()) { $discount += $getArticles[$key]["amountWithTax"] / 100 * $this->sSYSTEM->sUSERGROUPDATA["basketdiscount"]; } } elseif ($getArticles[$key]["modus"] == 3) { $getArticles[$key]["amountWithTax"] = round(1 * (round($price, 2) / 100 * (100 + $tax)), 2); // Basket discount } elseif ($getArticles[$key]["modus"] == 2) { $getArticles[$key]["amountWithTax"] = round(1 * (round($price, 2) / 100 * (100 + $tax)), 2); if ($this->sSYSTEM->sUSERGROUPDATA["basketdiscount"] && $this->sCheckForDiscount()) { $discount += $getArticles[$key]["amountWithTax"] / 100 * $this->sSYSTEM->sUSERGROUPDATA["basketdiscount"]; } } elseif ($getArticles[$key]["modus"] == 4 || $getArticles[$key]["modus"] == 10) { $getArticles[$key]["amountWithTax"] = round(1 * ($price / 100 * (100 + $tax)), 2); if ($this->sSYSTEM->sUSERGROUPDATA["basketdiscount"] && $this->sCheckForDiscount()) { $discount += $getArticles[$key]["amountWithTax"] / 100 * $this->sSYSTEM->sUSERGROUPDATA["basketdiscount"]; } } } $getArticles[$key]["amount"] = $quantity * round($price, 2); //reset purchaseunit and save the original value in purchaseunitTemp if ($getArticles[$key]["purchaseunit"] > 0) { $getArticles[$key]["purchaseunitTemp"] = $getArticles[$key]["purchaseunit"]; $getArticles[$key]["purchaseunit"] = 1; } // If price per unit is not referring to 1, calculate base-price // Choose 1000, quantity refers to 500, calculate price / 1000 * 500 as reference if ($getArticles[$key]["purchaseunit"] != 0) { $getArticles[$key]["itemInfo"] = $getArticles[$key]["purchaseunit"] . " {$getUnitData["description"]} / " . $this->moduleManager->Articles()->sFormatPrice($getArticles[$key]["amount"] / $quantity * $getArticles[$key]["purchaseunit"]); $getArticles[$key]["itemInfoArray"]["reference"] = $getArticles[$key]["purchaseunit"]; $getArticles[$key]["itemInfoArray"]["unit"] = $getUnitData; $getArticles[$key]["itemInfoArray"]["price"] = $this->moduleManager->Articles()->sFormatPrice($getArticles[$key]["amount"] / $quantity * $getArticles[$key]["purchaseunit"]); } if ($getArticles[$key]["modus"] == 2) { // Gutscheine if (!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"]) { $getArticles[$key]["amountnet"] = $quantity * round($price, 2); } else { $getArticles[$key]["amountnet"] = $quantity * round($netprice, 2); } } else { if (!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"]) { $getArticles[$key]["amountnet"] = $quantity * round($netprice, 2); } else { $getArticles[$key]["amountnet"] = $quantity * $netprice; } } $totalAmount += round($getArticles[$key]["amount"], 2); // Needed if shop is in net-mode $totalAmountWithTax += round($getArticles[$key]["amountWithTax"], 2); // Ignore vouchers and premiums by counting articles if (!$getArticles[$key]["modus"]) { $totalCount++; } $totalAmountNet += round($getArticles[$key]["amountnet"], 2); $getArticles[$key]["priceNumeric"] = $getArticles[$key]["price"]; $getArticles[$key]["price"] = $this->moduleManager->Articles()->sFormatPrice($getArticles[$key]["price"]); $getArticles[$key]["amount"] = $this->moduleManager->Articles()->sFormatPrice($getArticles[$key]["amount"]); $getArticles[$key]["amountnet"] = $this->moduleManager->Articles()->sFormatPrice($getArticles[$key]["amountnet"]); if (!empty($getArticles[$key]["purchaseunitTemp"])) { $getArticles[$key]["purchaseunit"] = $getArticles[$key]["purchaseunitTemp"]; $getArticles[$key]["itemInfo"] = $getArticles[$key]["purchaseunit"] . " {$getUnitData["description"]} / " . $this->moduleManager->Articles()->sFormatPrice(str_replace(",", ".", $getArticles[$key]["amount"]) / $quantity); } if ($getArticles[$key]["articleID"]) { // Article image if (!empty($getArticles[$key]["ob_attr1"])) { $getArticles[$key]["image"] = $this->moduleManager->Articles()->sGetConfiguratorImage($this->moduleManager->Articles()->sGetArticlePictures($getArticles[$key]["articleID"], false, $this->config->get('sTHUMBBASKET'), false, true), $getArticles[$key]["ob_attr1"]); } else { $getArticles[$key]["image"] = $this->moduleManager->Articles()->sGetArticlePictures($getArticles[$key]["articleID"], true, $this->config->get('sTHUMBBASKET'), $getArticles[$key]["ordernumber"]); } } // Links to details, basket $getArticles[$key]["linkDetails"] = $this->config->get('sBASEFILE') . "?sViewport=detail&sArticle=" . $getArticles[$key]["articleID"]; if ($getArticles[$key]["modus"] == 2) { $getArticles[$key]["linkDelete"] = $this->config->get('sBASEFILE') . "?sViewport=basket&sDelete=voucher"; } else { $getArticles[$key]["linkDelete"] = $this->config->get('sBASEFILE') . "?sViewport=basket&sDelete=" . $getArticles[$key]["id"]; } $getArticles[$key]["linkNote"] = $this->config->get('sBASEFILE') . "?sViewport=note&sAdd=" . $getArticles[$key]["ordernumber"]; $getArticles[$key] = $this->eventManager->filter('Shopware_Modules_Basket_GetBasket_FilterItemEnd', $getArticles[$key], array('subject' => $this, 'getArticles' => $getArticles)); } return array($getArticles, $totalAmount, $totalAmountWithTax, $totalCount, $totalAmountNet); }
/** * Helper function which checks the passed $selection parameter for empty. * If this is the case the function implements the fallback on the legacy * _POST access to get the configuration selection directly of the request object. * * Additionally the function removes empty array elements. * Array elements of the configuration selection can be empty, if the user resets the * different group selections. * * @param array $selection * @return array */ private function getCurrentSelection(array $selection) { if (empty($selection) && $this->frontController && $this->frontController->Request()->has('group')) { $selection = $this->frontController->Request()->getParam('group'); } foreach ($selection as $groupId => $optionId) { if (!$groupId || !$optionId) { unset($selection[$groupId]); } } return $selection; }
/** * @param array $category * @return string */ private function getCategoryCanonicalParams($category) { $request = $this->frontController->Request(); $page = $request->getQuery('sPage'); $emotion = $this->manager->getRepository('Shopware\\Models\\Emotion\\Emotion')->getCategoryBaseEmotionsQuery($category['id'])->getArrayResult(); $canonicalParams = array('sViewport' => $category['blog'] ? 'blog' : 'cat', 'sCategory' => $category['id']); if ($this->config->get('seoIndexPaginationLinks') && (!$emotion || $page)) { $canonicalParams['sPage'] = $page ?: 1; } return $canonicalParams; }