Advertisement
Guest User

Untitled

a guest
Jun 15th, 2014
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 69.53 KB | None | 0 0
  1. <?php
  2. /**
  3. * Shopware 4.0
  4. * Copyright © 2012 shopware AG
  5. *
  6. * According to our dual licensing model, this program can be used either
  7. * under the terms of the GNU Affero General Public License, version 3,
  8. * or under a proprietary license.
  9. *
  10. * The texts of the GNU Affero General Public License with an additional
  11. * permission and of our proprietary license can be found at and
  12. * in the LICENSE file you have received along with this program.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * "Shopware" is a registered trademark of shopware AG.
  20. * The licensing of the program under the AGPLv3 does not imply a
  21. * trademark license. Therefore any rights, title and interest in
  22. * our trademarks remain entirely with us.
  23. *
  24. * @category Shopware
  25. * @package Shopware_Core
  26. * @subpackage Class
  27. * @copyright Copyright (c) 2012, shopware AG (http://www.shopware.de)
  28. * @version $Id$
  29. * @author Stefan Hamann
  30. * @author $Author$
  31. * @deprecated
  32. */
  33.  
  34. /**
  35. * Deprecated Shopware Class that handles cart operations
  36. * Will be replaced towards to shopware 4.n
  37. *
  38. * todo@all: Documentation
  39. */
  40. class sBasket
  41. {
  42. var $sSYSTEM;
  43. var $sBASKET;
  44.  
  45. /**
  46. * @var Shopware_Components_Snippet_Manager
  47. */
  48. var $snippetObject;
  49.  
  50. public function __construct(){
  51. $this->snippetObject = Shopware()->Snippets()->getNamespace('frontend/basket/internalMessages');
  52. }
  53. /**
  54. * Get total turn-over of current users cart
  55. * @access public
  56. * @deprecated
  57. * @return array
  58. */
  59. public function sGetAmount(){
  60. return $this->sSYSTEM->sDB_CONNECTION->GetRow("SELECT SUM(quantity*(floor(price * 100 + .55)/100))
  61. AS totalAmount FROM s_order_basket WHERE sessionID=? GROUP BY sessionID",array($this->sSYSTEM->sSESSION_ID));
  62. }
  63.  
  64. /**
  65. * Get total turn-over of current users cart (only products)
  66. * @access public
  67. * @deprecated
  68. * @return array
  69. */
  70. public function sGetAmountArticles(){
  71. return $this->sSYSTEM->sDB_CONNECTION->GetRow("SELECT SUM(quantity*(floor(price * 100 + .55)/100))
  72. AS totalAmount FROM s_order_basket WHERE sessionID=? AND modus=0 GROUP BY sessionID",array($this->sSYSTEM->sSESSION_ID));
  73. }
  74.  
  75. /**
  76. * Check if all positions in cart are available
  77. * @access public
  78. * @deprecated
  79. * @return array
  80. */
  81. public function sCheckBasketQuantities(){
  82.  
  83. $sql = "
  84. SELECT
  85. (d.instock - b.quantity) as diffStock, b.ordernumber,
  86. a.laststock, IF(a.active=1, d.active, 0) as active
  87. FROM s_order_basket b
  88. LEFT JOIN s_articles_details d
  89. ON d.ordernumber = b.ordernumber
  90. AND d.articleID = b.articleID
  91. LEFT JOIN s_articles a
  92. ON a.id = d.articleID
  93. WHERE b.sessionID = ?
  94. AND b.modus = 0
  95. GROUP BY b.ordernumber
  96. ";
  97. $result = $this->sSYSTEM->sDB_CONNECTION->GetAll($sql,array($this->sSYSTEM->sSESSION_ID));
  98. $hideBasket = false;
  99. foreach ($result as $article){
  100. if (empty($article['active'])
  101. || (!empty($article['laststock']) && $article["diffStock"] < 0)){
  102. $hideBasket = true;
  103. $articles[$article["ordernumber"]]["OutOfStock"] = true;
  104. } else {
  105. $articles[$article["ordernumber"]]["OutOfStock"] = false;
  106. }
  107. }
  108. return array("hideBasket"=>$hideBasket,"articles"=>$articles);
  109. }
  110.  
  111. /**
  112. * Get cart-amount for certain products / suppliers
  113. * @access public
  114. * @deprecated
  115. * @return array
  116. */
  117. public function sGetAmountRestrictedArticles($articles,$supplier){
  118. if (!is_array($articles) && empty($supplier)) return $this->sGetAmountArticles();
  119. if (is_array($articles)){
  120. foreach ($articles as $article){
  121. $article = $article;
  122. $newArticles[] = $article;
  123. }
  124. $in = implode(",",$newArticles);
  125. $articleSQL = "ordernumber IN ($in) ";
  126. }
  127. if (!empty($supplier)){
  128. if (empty($articleSQL)){
  129. $articleSQL = "1 != 1 ";
  130. }
  131. $supplierSQL = "OR s_articles.supplierID = $supplier ";
  132. }
  133. return $this->sSYSTEM->sDB_CONNECTION->GetRow("SELECT SUM(quantity*(floor(price * 100 + .55)/100))
  134. AS totalAmount FROM s_order_basket, s_articles WHERE sessionID=? AND modus=0 AND s_order_basket.articleID=s_articles.id
  135. AND
  136. (
  137. $articleSQL
  138. $supplierSQL
  139. )
  140. GROUP BY sessionID",array($this->sSYSTEM->sSESSION_ID));
  141. }
  142.  
  143. /**
  144. * Update vouchers in cart
  145. * @access public
  146. * @deprecated
  147. * @return array
  148. */
  149. public function sUpdateVoucher()
  150. {
  151. $sql = 'SELECT id basketID, ordernumber, articleID as voucherID FROM s_order_basket WHERE modus=2 AND sessionID=?';
  152. $voucher = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql, array($this->sSYSTEM->sSESSION_ID));
  153. if(!empty($voucher))
  154. {
  155. $sql = 'SELECT vouchercode FROM s_emarketing_vouchers WHERE ordercode=?';
  156. $voucher['code'] = $this->sSYSTEM->sDB_CONNECTION->GetOne($sql, array($voucher['ordernumber']));
  157. if (empty($voucher['code']))
  158. {
  159. $sql = 'SELECT code FROM s_emarketing_voucher_codes WHERE id=?';
  160. $voucher['code'] = $this->sSYSTEM->sDB_CONNECTION->GetOne($sql, array($voucher['voucherID']));
  161. }
  162. $this->sDeleteArticle($voucher['basketID']);
  163. $this->sAddVoucher($voucher['code']);
  164. }
  165. }
  166. /**
  167. * Insert basket discount
  168. * @deprecated
  169. * @access public
  170. * @return void
  171. */
  172. public function sInsertDiscount () {
  173.  
  174. // Get possible discounts
  175. $getDiscounts = $this->sSYSTEM->sDB_CONNECTION->GetAll("
  176. SELECT basketdiscount, basketdiscountstart FROM s_core_customergroups_discounts
  177. WHERE groupID=?
  178. ORDER BY basketdiscountstart ASC
  179. ",array($this->sSYSTEM->sUSERGROUPDATA["id"]));
  180.  
  181.  
  182. $rs = $this->sSYSTEM->sDB_CONNECTION->Execute("
  183. DELETE FROM s_order_basket WHERE sessionID=? AND modus=3
  184. ",array($this->sSYSTEM->sSESSION_ID));
  185.  
  186. // No discounts
  187. if (!count($getDiscounts)){
  188. return;
  189. }
  190.  
  191. $basketAmount = $this->sSYSTEM->sDB_CONNECTION->GetOne("SELECT SUM(quantity*(floor(price * 100 + .55)/100))
  192. AS totalAmount FROM s_order_basket WHERE sessionID=? AND modus!=4 GROUP BY sessionID",array($this->sSYSTEM->sSESSION_ID));
  193.  
  194. if (!$basketAmount) return; // No articles in basket, return
  195.  
  196. if ($this->sSYSTEM->sCurrency["factor"]){
  197. }else {
  198. $factor = 1;
  199. }
  200.  
  201.  
  202. // Iterate through discounts and find nearly one
  203. foreach ($getDiscounts as $discountRow){
  204. if ($basketAmount<$discountRow["basketdiscountstart"]){
  205. break;
  206. }else {
  207. $basketDiscount = $discountRow["basketdiscount"];
  208. }
  209. }
  210.  
  211. if (!$basketDiscount) return;
  212.  
  213. $insertTime = date("Y-m-d H:i:s");
  214. $discount = $basketAmount / 100 * $basketDiscount;
  215. $discount = $discount * -1;
  216. $discount = round($discount,2);
  217.  
  218. if (!empty($this->sSYSTEM->sCONFIG["sTAXAUTOMODE"])){
  219. $tax = $this->sSYSTEM->sMODULES['sBASKET']->getMaxTax();
  220. }else {
  221. $tax = $this->sSYSTEM->sCONFIG['sDISCOUNTTAX'];
  222. }
  223.  
  224. if (!empty($this->sSYSTEM->sCONFIG["sTAXAUTOMODE"])){
  225. $tax = $this->sSYSTEM->sMODULES['sBASKET']->getMaxTax();
  226. }
  227. if (!$tax) $tax = 19;
  228.  
  229. if (!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"]){
  230. $discountNet = $discount;
  231. }else {
  232. $discountNet = round($discount / (100+$tax) * 100,3);
  233. }
  234.  
  235. // Add discount - info to user-account
  236. $this->sSYSTEM->sUSERGROUPDATA["basketdiscount"] = $basketDiscount;
  237. // --
  238. $name = isset($this->sSYSTEM->sCONFIG['sDISCOUNTNUMBER']) ? $this->sSYSTEM->sCONFIG['sDISCOUNTNUMBER']: "DISCOUNT";
  239.  
  240. $discountName = - $basketDiscount . ' % ' . $this->sSYSTEM->sCONFIG["sDISCOUNTNAME"];
  241.  
  242. $params = array(
  243. $this->sSYSTEM->sSESSION_ID,
  244. $discountName,
  245. 0,
  246. $name,
  247. 1,
  248. $discount,
  249. $discountNet,
  250. $tax,
  251. $insertTime,
  252. 3,
  253. $this->sSYSTEM->sCurrency["factor"]
  254. );
  255. $sql = "
  256. INSERT INTO s_order_basket (
  257. sessionID,
  258. articlename,
  259. articleID,
  260. ordernumber,
  261. quantity,
  262. price,
  263. netprice,
  264. tax_rate,
  265. datum,
  266. modus,
  267. currencyFactor
  268. )
  269. VALUES (
  270. ?,?,?,?,?,?,?,?,?,?,?)";
  271.  
  272. $insertDiscount = $this->sSYSTEM->sDB_CONNECTION->Execute($sql, $params);
  273.  
  274. }
  275.  
  276. /**
  277. * Check if any discount is in cart
  278. * @access public
  279. * @deprecated
  280. * @return void
  281. */
  282. public function sCheckForDiscount(){
  283. $rs = $this->sSYSTEM->sDB_CONNECTION->GetRow("
  284. SELECT id FROM s_order_basket WHERE sessionID=? AND modus=3
  285. ",array($this->sSYSTEM->sSESSION_ID));
  286.  
  287. if ($rs["id"]){
  288. return true;
  289. }else {
  290. return false;
  291. }
  292. }
  293.  
  294. /**
  295. * Add premium products to cart
  296. * @access public
  297. * @deprecated
  298. * @return bool|int
  299. */
  300. public function sInsertPremium()
  301. {
  302. static $last_premium;
  303.  
  304. $sBasketAmount = $this->sGetAmount();
  305. $sBasketAmount = empty($sBasketAmount["totalAmount"]) ? 0 :$sBasketAmount["totalAmount"];
  306. $sBasketAmount = (float)$sBasketAmount;
  307.  
  308. if(empty($this->sSYSTEM->_GET["sAddPremium"]))
  309. {
  310. $sql = "
  311. SELECT b.id
  312. FROM s_order_basket b
  313.  
  314. LEFT JOIN s_addon_premiums p
  315. ON p.id=b.articleID
  316. AND p.startprice <= ?
  317.  
  318. WHERE b.modus =1
  319. AND p.id IS NULL
  320. AND b.sessionID = ?
  321. ";
  322.  
  323. $deletePremium = Shopware()->Db()->fetchCol($sql, array($sBasketAmount, $this->sSYSTEM->sSESSION_ID));
  324. if(empty($deletePremium)) {
  325. return true;
  326. }
  327.  
  328. $deletePremium = Shopware()->Db()->quote($deletePremium);
  329. $sql= "DELETE FROM s_order_basket WHERE id IN ($deletePremium)";
  330. Shopware()->Db()->query($sql);
  331. return true;
  332. }
  333.  
  334. if (empty($this->sSYSTEM->_GET["sAddPremium"]))
  335. return false;
  336.  
  337. if (isset($last_premium) && $last_premium == $this->sSYSTEM->_GET["sAddPremium"])
  338. return false;
  339.  
  340. $last_premium = $this->sSYSTEM->_GET["sAddPremium"];
  341.  
  342. $this->sSYSTEM->sDB_CONNECTION->Execute("
  343. DELETE FROM s_order_basket WHERE sessionID='".$this->sSYSTEM->sSESSION_ID."' AND modus=1
  344. ");
  345.  
  346. $ordernumber = $this->sSYSTEM->sDB_CONNECTION->qstr($this->sSYSTEM->_GET["sAddPremium"]);
  347.  
  348. $sql = "
  349. SELECT p.id, d.ordernumber, a.id as articleID, a.name, d.additionaltext, p.ordernumber_export, a.configurator_set_id
  350. FROM
  351. s_addon_premiums p,
  352. s_articles_details d,
  353. s_articles a,
  354. s_articles_details d2
  355. WHERE d.ordernumber=$ordernumber
  356. AND p.startprice<=$sBasketAmount
  357. AND p.ordernumber=d2.ordernumber
  358. AND d2.articleID=d.articleID
  359. AND d.articleID=a.id
  360. ";
  361.  
  362. $premium = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql);
  363. if(empty($premium)) {
  364. return false;
  365. }
  366.  
  367. $premium = $this->sSYSTEM->sMODULES['sArticles']->sGetTranslation($premium,$premium["articleID"],"article",$this->sSYSTEM->sLanguage);
  368. if (!empty($premium['configurator_set_id'])) {
  369. $number = $premium['ordernumber'];
  370. } else {
  371. $number = $premium['ordernumber_export'];
  372. }
  373.  
  374. $sql = "
  375. INSERT INTO s_order_basket (
  376. sessionID, articlename, articleID, ordernumber, quantity, price, netprice,tax_rate, datum, modus, currencyFactor
  377. ) VALUES (
  378. ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?, ?
  379. )
  380. ";
  381.  
  382. $data = array(
  383. $this->sSYSTEM->sSESSION_ID,
  384. trim($premium["name"] . " " . $premium["additionaltext"]),
  385. $premium['id'],
  386. $number,
  387. 1,
  388. 0,
  389. 0,
  390. 0,
  391. 1,
  392. $this->sSYSTEM->sCurrency["factor"]
  393. );
  394. return Shopware()->Db()->query($sql, $data);
  395. }
  396.  
  397. /**
  398. * Get count of different positions from current cart
  399. * @access public
  400. * @deprecated
  401. * @return int - Anzahl Positionen
  402. */
  403. public function sCountArticles()
  404. {
  405. $sql = 'SELECT COUNT(*) FROM s_order_basket WHERE modus=0 AND sessionID=?';
  406. return $this->sSYSTEM->sDB_CONNECTION->GetOne($sql, array($this->sSYSTEM->sSESSION_ID));
  407. }
  408.  
  409. /**
  410. * Get the max used tax-rate in basket in percent
  411. * @deprecated
  412. * @return
  413. */
  414. public function getMaxTax(){
  415.  
  416. $sql = "
  417. SELECT
  418. MAX(tax_rate) as max_tax
  419. FROM s_order_basket b
  420. WHERE b.sessionID=? AND b.modus=0
  421. GROUP BY b.sessionID
  422. ";
  423. $taxRate = $this->sSYSTEM->sDB_CONNECTION->GetOne($sql,array(empty($this->sSYSTEM->sSESSION_ID) ? session_id() : $this->sSYSTEM->sSESSION_ID));
  424. return $taxRate;
  425. }
  426. /**
  427. * Add voucher to cart
  428. * @param string $sTicket - voucher code
  429. * @access public
  430. * @deprecated
  431. * @return array
  432. */
  433. public function sAddVoucher($sTicket,$BASKET=''){
  434. if (Enlight()->Events()->notifyUntil('Shopware_Modules_Basket_AddVoucher_Start', array('subject'=>$this,'code'=>$sTicket,"basket"=>$BASKET))){
  435. return false;
  436. }
  437.  
  438. $sTicket = stripslashes($sTicket);
  439. $sTicket = strtolower($sTicket);
  440. $sql = "
  441. SELECT * FROM s_emarketing_vouchers WHERE modus != 1 AND LOWER(vouchercode)=?
  442. AND ((valid_to>=now() AND valid_from<=now()) OR valid_to is NULL)
  443. ";
  444.  
  445. $ticketResult = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql,array($sTicket));
  446.  
  447. // Check if voucher was already cashed
  448. if ($this->sSYSTEM->_SESSION["sUserId"] && $ticketResult["id"]){
  449. $userid = $this->sSYSTEM->_SESSION["sUserId"];
  450. $sql = "
  451. SELECT s_order_details.id AS id FROM s_order, s_order_details
  452. WHERE s_order.userID = $userid AND s_order_details.orderID=s_order.id
  453. AND s_order_details.articleordernumber = '{$ticketResult["ordercode"]}'
  454. AND s_order_details.ordernumber!='0'
  455. ";
  456.  
  457. $queryVoucher = $this->sSYSTEM->sDB_CONNECTION->GetAll($sql);
  458. if (count($queryVoucher)>=$ticketResult["numorder"] && !$ticketResult["modus"]){
  459.  
  460. $sErrorMessages[] = $this->snippetObject->get('VoucherFailureAlreadyUsed','This voucher was used in an previous order');
  461.  
  462. return array("sErrorFlag"=>true,"sErrorMessages"=>$sErrorMessages);
  463. }
  464. }
  465.  
  466. if ($ticketResult["id"]){
  467. //echo "NO INDIVIDUAL CODE $sTicket";
  468. // Check if ticket is available anymore
  469. $countTicket = $this->sSYSTEM->sDB_CONNECTION->GetRow("
  470. SELECT COUNT(id) AS vouchers FROM s_order_details WHERE articleordernumber='{$ticketResult["ordercode"]}'
  471. AND s_order_details.ordernumber!='0'
  472. ");
  473. } else {
  474. // Check for individual voucher - code
  475. $sql = "
  476. SELECT s_emarketing_voucher_codes.id AS id, s_emarketing_voucher_codes.code AS vouchercode,description, numberofunits,customergroup, value,restrictarticles, minimumcharge, shippingfree, bindtosupplier,
  477. taxconfig,
  478. valid_from,valid_to,ordercode, modus,percental,strict,subshopID FROM s_emarketing_vouchers, s_emarketing_voucher_codes
  479. WHERE
  480. modus = 1
  481. AND
  482. s_emarketing_vouchers.id = s_emarketing_voucher_codes.voucherID
  483. AND
  484. LOWER(code) = ?
  485. AND
  486. cashed != 1
  487. AND ((s_emarketing_vouchers.valid_to>=now() AND s_emarketing_vouchers.valid_from<=now()) OR s_emarketing_vouchers.valid_to is NULL)
  488. ";
  489. $ticketResult = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql,array($sTicket));
  490. if ($ticketResult["description"]){
  491. $indivualCode = true;
  492. } else {
  493. $indivualCode = false;
  494. }
  495. }
  496.  
  497.  
  498. // Check if ticket exists
  499. if (!count($ticketResult) || !$sTicket || ($ticketResult["numberofunits"]<=$countTicket["vouchers"] && !$indivualCode)){
  500. $sErrorMessages[] = $this->snippetObject->get('VoucherFailureNotFound','Voucher could not be found or is not valid anymore');
  501. return array("sErrorFlag"=>true,"sErrorMessages"=>$sErrorMessages);
  502. }
  503.  
  504. if (!empty($ticketResult["strict"])){
  505. $restrictDiscount = true;
  506. }else {
  507. $restrictDiscount = false;
  508. }
  509.  
  510. if (!empty($ticketResult["subshopID"])){
  511. if ($this->sSYSTEM->sSubShop["id"] != $ticketResult["subshopID"]){
  512. $sErrorMessages[] = $this->snippetObject->get('VoucherFailureNotFound','Voucher could not be found or is not valid anymore');
  513. return array("sErrorFlag"=>true,"sErrorMessages"=>$sErrorMessages);
  514. }
  515. }
  516.  
  517. // Check if any voucher is already in basket
  518. $chkBasket = $this->sSYSTEM->sDB_CONNECTION->GetRow("
  519. SELECT id FROM s_order_basket WHERE sessionID='".$this->sSYSTEM->sSESSION_ID."' AND modus=2
  520. ");
  521.  
  522.  
  523. if (count($chkBasket)){
  524. $sErrorMessages[] = $this->snippetObject->get('VoucherFailureOnlyOnes','Only one voucher can be processed in order');
  525. return array("sErrorFlag"=>true,"sErrorMessages"=>$sErrorMessages);
  526. }
  527. // Restrict to customergroup
  528. if (!empty($ticketResult["customergroup"])) {
  529. $userid = $this->sSYSTEM->_SESSION["sUserId"];
  530.  
  531. if (!empty($userid)) {
  532. // Get customergroup
  533. $queryCustomergroup = $this->sSYSTEM->sDB_CONNECTION->GetRow("
  534. SELECT s_core_customergroups.id, customergroup FROM s_user, s_core_customergroups WHERE s_user.id=$userid
  535. AND s_user.customergroup = s_core_customergroups.groupkey
  536. ");
  537. }
  538. $customergroup = $queryCustomergroup["customergroup"];
  539. if ($customergroup != $ticketResult["customergroup"] && $ticketResult["customergroup"] != $queryCustomergroup["id"] && $ticketResult["customergroup"] != $this->sSYSTEM->sUSERGROUPDATA["id"]) {
  540. $sErrorMessages[] = $this->snippetObject->get('VoucherFailureCustomerGroup','This voucher is not available for your customergroup');
  541. return array("sErrorFlag" => true, "sErrorMessages" => $sErrorMessages);
  542. }
  543. }
  544.  
  545. // Restrict to articles
  546. if (!empty($ticketResult["restrictarticles"]) && strlen($ticketResult["restrictarticles"])>5){
  547. $restrictedArticles = explode(";",$ticketResult["restrictarticles"]);
  548. if (count($restrictedArticles)==0) $restrictedArticles[] = $ticketResult["restrictarticles"];
  549. foreach ($restrictedArticles as $k => $restrictedArticle) $restrictedArticles[$k] = (string)$this->sSYSTEM->sDB_CONNECTION->qstr($restrictedArticle);
  550.  
  551. $sql = "
  552. SELECT id FROM s_order_basket WHERE sessionID='".$this->sSYSTEM->sSESSION_ID."' AND modus=0
  553. AND ordernumber IN (".implode(",",$restrictedArticles).")
  554. ";
  555.  
  556. $getOrdernumbers = $this->sSYSTEM->sDB_CONNECTION->GetOne($sql);
  557. $foundMatchingArticle = false;
  558.  
  559. if (!empty($getOrdernumbers)) $foundMatchingArticle = true;
  560.  
  561. if (empty($foundMatchingArticle)){
  562.  
  563. $sErrorMessages[] = $this->snippetObject->get('VoucherFailureProducts','This voucher is only available in combination with certain products');
  564. return array("sErrorFlag"=>true,"sErrorMessages"=>$sErrorMessages);
  565. }
  566. }
  567. // Restrict to supplier
  568. if ($ticketResult["bindtosupplier"]){
  569. $searchHersteller = $ticketResult["bindtosupplier"];
  570. $sql = "
  571. SELECT s_order_basket.id FROM s_order_basket, s_articles, s_articles_supplier WHERE
  572. s_order_basket.articleID=s_articles.id AND s_articles.supplierID=$searchHersteller
  573. AND s_order_basket.sessionID='".$this->sSYSTEM->sSESSION_ID."'
  574. ";
  575.  
  576. $chkHersteller = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql);
  577.  
  578. if (!count($chkHersteller)){
  579. // Name des Herstellers abfragen
  580. $queryHersteller = $this->sSYSTEM->sDB_CONNECTION->GetRow("
  581. SELECT name FROM s_articles_supplier WHERE id=$searchHersteller
  582. ");
  583.  
  584. $sErrorMessages[] = str_replace("{sSupplier}",$queryHersteller["name"],$this->snippetObject->get('VoucherFailureSupplier','This voucher is only available for products from {sSupplier}'));
  585. return array("sErrorFlag"=>true,"sErrorMessages"=>$sErrorMessages);
  586. }
  587. }
  588.  
  589. if (!empty($restrictDiscount) && (!empty($restrictedArticles) || !empty($searchHersteller))){
  590. $amount = $this->sGetAmountRestrictedArticles($restrictedArticles,$searchHersteller);
  591. }else {
  592. $amount = $this->sGetAmountArticles();
  593. }
  594. if ($this->sSYSTEM->sCurrency["factor"] && empty($ticketResult["percental"])){
  595. $factor = $this->sSYSTEM->sCurrency["factor"];
  596. $ticketResult["value"] *= $factor;
  597. }else {
  598. $factor = 1;
  599. }
  600.  
  601. if (($amount["totalAmount"]/$factor) < $ticketResult["minimumcharge"]){
  602.  
  603. $sErrorMessages[] = str_replace("{sMinimumCharge}",$ticketResult["minimumcharge"],$this->snippetObject->get('VoucherFailureMinimumCharge','The minimum charge for this voucher is {sMinimumCharge}'));
  604. return array("sErrorFlag"=>true,"sErrorMessages"=>$sErrorMessages);
  605. }
  606.  
  607. $timeInsert = date("Y-m-d H:i:s");
  608.  
  609. $vouchername = $this->sSYSTEM->sCONFIG['sVOUCHERNAME'];
  610. if ($ticketResult["percental"]){
  611. $value = $ticketResult["value"];
  612. $vouchername .= " ".$value." %";
  613. $ticketResult["value"] = ($amount["totalAmount"] / 100) * floatval($value);
  614. }
  615.  
  616.  
  617. // Free tax configuration for vouchers
  618. // Trac ticket 4708 st.hamann
  619. $taxRate = 0;
  620. if ((!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"]) || $ticketResult["taxconfig"]=="none"){
  621. // if net customergroup - calculate without tax
  622. $tax = $ticketResult["value"] * -1;
  623. if ($ticketResult["taxconfig"] == "default" || empty($ticketResult["taxconfig"])){
  624. $taxRate = $this->sSYSTEM->sCONFIG['sVOUCHERTAX'];
  625. }elseif ($ticketResult["taxconfig"]=="auto"){
  626. $taxRate =$this->getMaxTax();
  627.  
  628. }elseif (intval($ticketResult["taxconfig"])){
  629. $temporaryTax =$ticketResult["taxconfig"];
  630. $getTaxRate = $this->sSYSTEM->sDB_CONNECTION->getOne("
  631. SELECT tax FROM s_core_tax WHERE id = ?
  632. ",array($temporaryTax));
  633. $taxRate = $getTaxRate;
  634. }
  635. }else {
  636. if ($ticketResult["taxconfig"] == "default" || empty($ticketResult["taxconfig"])){
  637. $tax = round($ticketResult["value"]/(100+$this->sSYSTEM->sCONFIG['sVOUCHERTAX'])*100,3)*-1;
  638. $taxRate = $this->sSYSTEM->sCONFIG['sVOUCHERTAX'];
  639. // Pre 3.5.4 behaviour
  640. }elseif ($ticketResult["taxconfig"]=="auto"){
  641. // Check max. used tax-rate from basket
  642. $tax = $this->getMaxTax();
  643. $taxRate = $tax;
  644. $tax = round($ticketResult["value"]/(100+$tax)*100,3)*-1;
  645. }elseif (intval($ticketResult["taxconfig"])){
  646. // Fix defined tax
  647. $temporaryTax =$ticketResult["taxconfig"];
  648. $getTaxRate = $this->sSYSTEM->sDB_CONNECTION->getOne("
  649. SELECT tax FROM s_core_tax WHERE id = ?
  650. ",array($temporaryTax));
  651. $taxRate = $getTaxRate;
  652. $tax = round($ticketResult["value"]/(100+$getTaxRate)*100,3)*-1;
  653. }else {
  654. // No tax
  655. $tax = $ticketResult["value"] * -1;
  656. }
  657. }
  658.  
  659. $ticketResult["value"] = $ticketResult["value"] * -1;
  660.  
  661. if ($ticketResult["shippingfree"]){
  662. $shippingfree = "1";
  663. }else {
  664. $shippingfree = "0";
  665. }
  666.  
  667. $sql = "
  668. INSERT INTO s_order_basket (sessionID, articlename, articleID, ordernumber, shippingfree, quantity, price, netprice,tax_rate, datum, modus, currencyFactor)
  669. VALUES (?,?,?,?,?,1,?,?,?,?,2,?)
  670. ";
  671. $params = array (
  672. $this->sSYSTEM->sSESSION_ID,
  673. $vouchername,
  674. $ticketResult["id"],
  675. $ticketResult["ordercode"],
  676. $shippingfree,
  677. $ticketResult["value"],
  678. $tax,
  679. $taxRate,
  680. $timeInsert,
  681. $this->sSYSTEM->sCurrency["factor"]
  682. );
  683. $sql = Enlight()->Events()->filter('Shopware_Modules_Basket_AddVoucher_FilterSql',$sql, array('subject'=>$this,"params"=>$params,"voucher"=>$ticketResult,"name"=>$vouchername,"shippingfree"=>$shippingfree,"tax"=>$tax));
  684.  
  685.  
  686. if (!$this->sSYSTEM->sDB_CONNECTION->Execute($sql,$params)){
  687. return false;
  688. }
  689.  
  690. return true;
  691. }
  692.  
  693. /**
  694. * Get total weight of products in cart
  695. * @access public
  696. * @deprecated
  697. * @return double - weight in kilogram
  698. */
  699. public function sGetBasketWeight()
  700. {
  701. $sql = '
  702. SELECT SUM(d.weight*b.quantity) as weight
  703. FROM s_order_basket b
  704.  
  705. LEFT JOIN s_articles a
  706. ON b.articleID=a.id
  707. AND b.modus=0
  708. AND b.esdarticle=0
  709.  
  710. LEFT JOIN s_articles_details d
  711. ON (d.ordernumber=b.ordernumber)
  712. AND d.articleID=a.id
  713.  
  714. WHERE b.sessionID=?
  715. ';
  716. $weight = $this->sSYSTEM->sDB_CONNECTION->GetOne($sql, array($this->sSYSTEM->sSESSION_ID));
  717. return $weight;
  718. }
  719.  
  720.  
  721. /**
  722. * Get articleId of all products from cart
  723. * @access public
  724. * @deprecated
  725. * @return array
  726. */
  727. public function sGetBasketIds(){
  728. $getArticles = $this->sSYSTEM->sDB_CONNECTION->GetAll("SELECT DISTINCT articleID FROM s_order_basket WHERE sessionID=?
  729. AND modus=0
  730. ORDER BY modus ASC, datum DESC",array($this->sSYSTEM->sSESSION_ID));
  731.  
  732. foreach ($getArticles as $article){
  733. $articles[] = $article["articleID"];
  734. }
  735.  
  736. return $articles;
  737. }
  738.  
  739. /**
  740. * Check if minimum charging is reached
  741. * @access public
  742. * @deprecated
  743. * @return void
  744. */
  745.  
  746. public function sCheckMinimumCharge(){
  747. if ($this->sSYSTEM->sUSERGROUPDATA["minimumorder"] && !$this->sSYSTEM->sUSERGROUPDATA["minimumordersurcharge"]){
  748. $amount = $this->sGetAmount();
  749. if ($amount["totalAmount"]<($this->sSYSTEM->sUSERGROUPDATA["minimumorder"]*$this->sSYSTEM->sCurrency["factor"])){
  750. return ($this->sSYSTEM->sUSERGROUPDATA["minimumorder"]*$this->sSYSTEM->sCurrency["factor"]);
  751. }else {
  752. return false;
  753. }
  754. }
  755. return false;
  756. }
  757.  
  758. /**
  759. * Add surcharge for payment-means to cart
  760. * @access public
  761. * @deprecated
  762. * @return array
  763. */
  764. public function sInsertSurcharge(){
  765. $name = isset($this->sSYSTEM->sCONFIG['sSURCHARGENUMBER']) ? $this->sSYSTEM->sCONFIG['sSURCHARGENUMBER']: "SURCHARGE";
  766.  
  767. // Delete previous inserted discounts
  768. $this->sSYSTEM->sDB_CONNECTION->Execute("
  769. DELETE FROM s_order_basket WHERE sessionID=? AND ordernumber=?
  770. ",array($this->sSYSTEM->sSESSION_ID,$name));
  771.  
  772. if (!$this->sCountArticles()) return false;
  773.  
  774. if ($this->sSYSTEM->sUSERGROUPDATA["minimumorder"] && $this->sSYSTEM->sUSERGROUPDATA["minimumordersurcharge"]){
  775.  
  776. $amount = $this->sGetAmount();
  777.  
  778. if ($amount["totalAmount"]<$this->sSYSTEM->sUSERGROUPDATA["minimumorder"]){
  779.  
  780. if (!empty($this->sSYSTEM->sCONFIG["sTAXAUTOMODE"])){
  781. $tax = $this->sSYSTEM->sMODULES['sBASKET']->getMaxTax();
  782. }else {
  783. $tax = $this->sSYSTEM->sCONFIG['sDISCOUNTTAX'];
  784. }
  785.  
  786. if (empty($tax)) $tax = 19;
  787.  
  788. if ((!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"])){
  789. $discountNet = $this->sSYSTEM->sUSERGROUPDATA["minimumordersurcharge"];
  790. }else {
  791. $discountNet = round($this->sSYSTEM->sUSERGROUPDATA["minimumordersurcharge"] / (100+$tax) * 100,3);
  792. }
  793.  
  794. if ($this->sSYSTEM->sCurrency["factor"]){
  795. $factor = $this->sSYSTEM->sCurrency["factor"];
  796. $discountNet /= $factor;
  797. }else {
  798. $factor = 1;
  799. }
  800.  
  801. $surcharge = $this->sSYSTEM->sUSERGROUPDATA["minimumordersurcharge"]/$factor;
  802.  
  803. $params = array(
  804. $this->sSYSTEM->sSESSION_ID,
  805. $this->sSYSTEM->sCONFIG["sSURCHARGENAME"],
  806. $name,
  807. $surcharge,
  808. $discountNet,
  809. $tax,
  810. $this->sSYSTEM->sCurrency["factor"]
  811. );
  812.  
  813. $this->sSYSTEM->sDB_CONNECTION->Execute("
  814. INSERT INTO s_order_basket (sessionID, articlename, articleID, ordernumber, quantity,price,netprice,tax_rate,datum,modus,currencyFactor)
  815. VALUES (
  816. ?,
  817. ?,
  818. 0,
  819. ?,
  820. 1,
  821. ?,
  822. ?,
  823. ?,
  824. now(),
  825. 4,
  826. ?
  827. )
  828. ",$params);
  829.  
  830. }
  831. }
  832. }
  833.  
  834. /**
  835. * Add percentual surcharge
  836. * @access public
  837. * @deprecated
  838. * @return void
  839. */
  840. public function sInsertSurchargePercent()
  841. {
  842. if (!$this->sSYSTEM->_SESSION["sUserId"]){
  843. if (!$this->sSYSTEM->_SESSION["sPaymentID"]){
  844. return false;
  845. }else {
  846. $paymentInfo = $this->sSYSTEM->sDB_CONNECTION->GetRow("
  847. SELECT debit_percent FROM s_core_paymentmeans WHERE id=?",array($this->sSYSTEM->_SESSION["sPaymentID"]));
  848. }
  849. } else {
  850. $userData = $this->sSYSTEM->sDB_CONNECTION->GetRow("SELECT paymentID FROM s_user WHERE id=?",array(intval($this->sSYSTEM->_SESSION["sUserId"])));
  851. $paymentInfo = $this->sSYSTEM->sDB_CONNECTION->GetRow("
  852. SELECT debit_percent FROM s_core_paymentmeans WHERE id=?",array($userData["paymentID"]));
  853.  
  854. }
  855.  
  856. $name = isset($this->sSYSTEM->sCONFIG['sPAYMENTSURCHARGENUMBER']) ? $this->sSYSTEM->sCONFIG['sPAYMENTSURCHARGENUMBER']: "PAYMENTSURCHARGE";
  857. // Depends on payment-mean
  858. $percent = $paymentInfo["debit_percent"];
  859.  
  860. $rs = $this->sSYSTEM->sDB_CONNECTION->Execute("
  861. DELETE FROM s_order_basket WHERE sessionID=? AND ordernumber=?
  862. ",array($this->sSYSTEM->sSESSION_ID,$name));
  863.  
  864. if (!$this->sCountArticles()) return false;
  865.  
  866. if (!empty($percent)){
  867.  
  868. $amount = $this->sGetAmount();
  869.  
  870. if ($percent>=0){
  871. $surchargename = $this->sSYSTEM->sCONFIG["sPAYMENTSURCHARGEADD"];
  872. }else {
  873. $surchargename = $this->sSYSTEM->sCONFIG["sPAYMENTSURCHARGEDEV"];
  874. }
  875. //print_r($amount); exit;
  876. $surcharge = $amount["totalAmount"] / 100 * $percent;
  877. //echo $amount["totalAmount"]." - ".$surcharge." <br />";
  878. if (!empty($this->sSYSTEM->sCONFIG["sTAXAUTOMODE"])){
  879. $tax = $this->getMaxTax();
  880. }else {
  881. $tax = $this->sSYSTEM->sCONFIG['sDISCOUNTTAX'];
  882. }
  883.  
  884. if ((!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"])){
  885. $discountNet = $surcharge;
  886. }else {
  887. $discountNet = round($surcharge / (100+$tax) * 100,3);
  888. }
  889.  
  890. if ($this->sSYSTEM->sCurrency["factor"]){
  891. $factor = $this->sSYSTEM->sCurrency["factor"];
  892. /*$discountNet /= $factor;
  893. $surcharge /= $factor;*/
  894. }else {
  895. $factor = 1;
  896. }
  897.  
  898.  
  899. $params = array(
  900. $this->sSYSTEM->sSESSION_ID,
  901. $surchargename,
  902. $name,
  903. $surcharge,
  904. $discountNet,
  905. $tax,
  906. $this->sSYSTEM->sCurrency["factor"]
  907.  
  908. );
  909.  
  910. $this->sSYSTEM->sDB_CONNECTION->Execute("
  911. INSERT INTO s_order_basket (sessionID, articlename, articleID, ordernumber, quantity,price,netprice,tax_rate, datum,modus,currencyFactor)
  912. VALUES (?,
  913. ?,
  914. 0,
  915. ?,
  916. 1,
  917. ?,
  918. ?,
  919. ?,
  920. now(),
  921. 4,
  922. ?
  923. )
  924. ",$params);
  925.  
  926.  
  927. }
  928. }
  929.  
  930. /**
  931. * Fetch count of products in basket
  932. * @access public
  933. * @deprecated
  934. * @return array
  935. */
  936. public function sCountBasket(){
  937. $getArticles = $this->sSYSTEM->sDB_CONNECTION->GetAll("SELECT id FROM s_order_basket WHERE sessionID=? AND modus=0
  938. ",array($this->sSYSTEM->sSESSION_ID));
  939. return count($getArticles);
  940. }
  941.  
  942. /**
  943. * Get all basket positions
  944. * @access public
  945. * @deprecated
  946. * @return array
  947. */
  948. public function sGetBasket(){
  949. // Init variables
  950. $discount = 0; $totalAmount = 0; $totalAmountWithTax = 0; $totalAmountNet = 0; $totalCount = 0;
  951.  
  952. // Refresh basket-prices
  953. $basketData = $this->sSYSTEM->sDB_CONNECTION->GetAll("
  954. SELECT id,modus, quantity FROM s_order_basket
  955. WHERE sessionID=?",array($this->sSYSTEM->sSESSION_ID));
  956. foreach ($basketData as $basketContent){
  957. if (empty($basketContent["modus"])){
  958. $this->sUpdateArticle ($basketContent["id"],$basketContent["quantity"]);
  959. }
  960. }
  961.  
  962.  
  963. // Check, if we have some free products for the client
  964. $this->sInsertPremium();
  965.  
  966. // Delete previous given discounts
  967. if (empty($this->sSYSTEM->sCONFIG['sPREMIUMSHIPPIUNG']))
  968. {
  969. $rs = $this->sSYSTEM->sDB_CONNECTION->Execute("
  970. DELETE FROM s_order_basket WHERE sessionID=? AND modus=3
  971. ",array($this->sSYSTEM->sSESSION_ID));
  972. }
  973. // Check for surcharges
  974. $this->sInsertSurcharge();
  975. // Check for skonto / percent surcharges
  976. $this->sInsertSurchargePercent();
  977.  
  978. // Calculate global basket discount
  979. $this->sInsertDiscount();
  980.  
  981. $sql = "
  982. SELECT s_order_basket.*, ad.packunit, ad.minpurchase,taxID,ad.instock AS `instock`,
  983. suppliernumber,
  984. ad.maxpurchase,
  985. ad.purchasesteps,
  986. ad.purchaseunit,
  987. ad.unitID,
  988. laststock,
  989. ad.shippingtime,
  990. ad.releasedate,
  991. ad.releasedate AS sReleaseDate,stockmin, su.description AS itemUnit,
  992. s_order_basket_attributes.attribute1 as ob_attr1,
  993. s_order_basket_attributes.attribute2 as ob_attr2,
  994. s_order_basket_attributes.attribute3 as ob_attr3,
  995. s_order_basket_attributes.attribute4 as ob_attr4,
  996. s_order_basket_attributes.attribute5 as ob_attr5,
  997. s_order_basket_attributes.attribute6 as ob_attr6
  998. FROM s_order_basket
  999. LEFT JOIN s_articles_details AS ad ON ad.ordernumber = s_order_basket.ordernumber
  1000. LEFT JOIN s_articles a ON (a.id = ad.articleID)
  1001. LEFT JOIN s_core_units su ON su.id = ad.unitID
  1002. LEFT JOIN s_order_basket_attributes ON s_order_basket.id = s_order_basket_attributes.basketID
  1003. WHERE sessionID=?
  1004. ORDER BY id ASC, datum DESC
  1005. ";
  1006. $sql = Enlight()->Events()->filter('Shopware_Modules_Basket_GetBasket_FilterSQL', $sql, array('subject'=>$this));
  1007.  
  1008.  
  1009. $getArticles = $this->sSYSTEM->sDB_CONNECTION->GetAll($sql,array($this->sSYSTEM->sSESSION_ID));
  1010. $countItems = count($getArticles);
  1011.  
  1012. if (!empty($countItems)){
  1013. // Reformating data, add additional datafields to array
  1014. foreach ($getArticles as $key => $value){
  1015. $getArticles[$key] = Enlight()->Events()->filter('Shopware_Modules_Basket_GetBasket_FilterItemStart', $getArticles[$key], array('subject'=>$this,'getArticles'=>$getArticles));
  1016.  
  1017. if (empty($getArticles[$key]["modus"])){
  1018. $getArticles[$key]["shippinginfo"] = true;
  1019. }else {
  1020. $getArticles[$key]["shippinginfo"] = false;
  1021. }
  1022. if (!empty($getArticles[$key]["releasedate"]) && strtotime($getArticles[$key]["releasedate"]) <= time()){
  1023. $getArticles[$key]["sReleaseDate"] = $getArticles[$key]["releasedate"] = "";
  1024. }
  1025. $getArticles[$key]["esd"] = $getArticles[$key]["esdarticle"];
  1026. if (empty($getArticles[$key]["minpurchase"])) $getArticles[$key]["minpurchase"] = 1;
  1027. if (empty($getArticles[$key]["purchasesteps"])) $getArticles[$key]["purchasesteps"] = 1;
  1028. if ($getArticles[$key]["purchasesteps"]<=0) unset($getArticles[$key]["purchasesteps"]);
  1029.  
  1030. if (empty($getArticles[$key]["maxpurchase"])) {
  1031. $getArticles[$key]["maxpurchase"] = $this->sSYSTEM->sCONFIG['sMAXPURCHASE'];
  1032. }
  1033. if(!empty($getArticles[$key]["laststock"])
  1034. && $getArticles[$key]["instock"] < $getArticles[$key]["maxpurchase"]) {
  1035. $getArticles[$key]["maxpurchase"] = $getArticles[$key]["instock"];
  1036. }
  1037.  
  1038. // Get additional basket meta data for each product
  1039. if ($getArticles[$key]["modus"] == 0){
  1040. /**
  1041. {$sBasketItem.additional_details.properties} --> Eigenschaften/Filter
  1042. {$sBasketItem.additional_details.description} --> Artikel Kurzbeschreibung
  1043. {$sBasketItem.additional_details.description_long} --> Artikel Langbeschreibung
  1044. {$sBasketItem.additional_details.attrX} --> Artikel Attribut (X ist zu ersetzen durch das gewünschte Attribut 1-20)
  1045. {$sBasketItem.additional_details.purchaseunit} --> Inhalt (Grundpreisberechnung)
  1046. {$sBasketItem.additional_details.sUnit.unit} --> Einheit (Grundpreisberechnung)
  1047. {$sBasketItem.additional_details.referenceprice|currency} --> Grundpreis
  1048. * SELECT a.description, a.description_long, at.*, ad.purchaseunit,
  1049. */
  1050. $tempArticle = Shopware()->Modules()->Articles()->sGetProductByOrdernumber($value['ordernumber']);
  1051.  
  1052. if(empty($tempArticle)) {
  1053. $getArticles[$key]["additional_details"] = array("properties"=>array());
  1054. }else {
  1055. $getArticles[$key]['additional_details'] = $tempArticle;
  1056. $properties = '';
  1057. foreach($getArticles[$key]['additional_details']['sProperties'] as $property) {
  1058. $properties .= $property['name'] . ':&nbsp;' . $property['value'] . ',&nbsp;';
  1059. }
  1060. $getArticles[$key]['additional_details']['properties'] = substr($properties, 0, -7);
  1061. }
  1062. }
  1063.  
  1064. // If unitID is set, query it
  1065. if (!empty($getArticles[$key]["unitID"])){
  1066. $getUnitData = $this->sSYSTEM->sMODULES['sArticles']->sGetUnit($getArticles[$key]["unitID"]);
  1067. $getArticles[$key]["itemUnit"] = $getUnitData["description"];
  1068. } else {
  1069. unset($getArticles[$key]["unitID"]);
  1070. }
  1071.  
  1072. if (!empty($getArticles[$key]["packunit"])){
  1073. $getPackUnit = $this->sSYSTEM->sMODULES['sArticles']->sGetTranslation(array(),$getArticles[$key]["articleID"],"article",$this->sSYSTEM->sLanguage);
  1074. if (!empty($getPackUnit["packunit"])){
  1075. $getArticles[$key]["packunit"] = $getPackUnit["packunit"];
  1076. }
  1077. }
  1078.  
  1079. $quantity = $getArticles[$key]["quantity"];
  1080. $price = $getArticles[$key]["price"];
  1081. $netprice = $getArticles[$key]["netprice"];
  1082.  
  1083. if ($value["modus"]==2){
  1084. $sql = "
  1085. SELECT vouchercode,taxconfig FROM s_emarketing_vouchers WHERE ordercode='{$getArticles[$key]["ordernumber"]}'
  1086. ";
  1087.  
  1088. $ticketResult = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql);
  1089.  
  1090. if (!$ticketResult["vouchercode"]){
  1091. // Query Voucher-Code
  1092. $queryVoucher = $this->sSYSTEM->sDB_CONNECTION->GetRow("
  1093. SELECT code FROM s_emarketing_voucher_codes WHERE id = {$getArticles[$key]["articleID"]}
  1094. AND cashed!=1
  1095. ");
  1096. $ticketResult["vouchercode"] = $queryVoucher["code"];
  1097. }
  1098. $this->sDeleteArticle($getArticles[$key]["id"]);
  1099.  
  1100. //if voucher was deleted, do not restore
  1101. if($this->sSYSTEM->_GET['sDelete'] != 'voucher')
  1102. {
  1103. $this->sAddVoucher($ticketResult["vouchercode"]);
  1104.  
  1105. }
  1106. }
  1107.  
  1108. $tax = $value["tax_rate"];
  1109.  
  1110. // If shop is in net mode, we have to consider
  1111. // the tax separately
  1112. if (($this->sSYSTEM->sCONFIG['sARTICLESOUTPUTNETTO'] && !$this->sSYSTEM->sUSERGROUPDATA["tax"]) || (!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"]))
  1113. {
  1114. if (empty($value["modus"])){
  1115.  
  1116. $priceWithTax = round($netprice,2) / 100 * (100+$tax);
  1117.  
  1118. $getArticles[$key]["amountWithTax"] = $quantity * $priceWithTax;
  1119. // If basket comprised any discount, calculate brutto-value for the discount
  1120. if ($this->sSYSTEM->sUSERGROUPDATA["basketdiscount"] && $this->sCheckForDiscount()){
  1121. $discount += ($getArticles[$key]["amountWithTax"]/100*$this->sSYSTEM->sUSERGROUPDATA["basketdiscount"]);
  1122. }
  1123.  
  1124. }elseif ($value["modus"]==3){
  1125. $getArticles[$key]["amountWithTax"] = round(1 * (round($price,2) / 100 * (100+$tax)),2);
  1126. // Basket discount
  1127. }elseif ($value["modus"]==2){
  1128. $getArticles[$key]["amountWithTax"] = round(1 * (round($price,2) / 100 * (100+$tax)),2);
  1129.  
  1130. if ($this->sSYSTEM->sUSERGROUPDATA["basketdiscount"] && $this->sCheckForDiscount()){
  1131. $discount += ($getArticles[$key]["amountWithTax"]/100*($this->sSYSTEM->sUSERGROUPDATA["basketdiscount"]));
  1132. }
  1133. } elseif ($value["modus"]==4 || $value["modus"]==10){
  1134. $getArticles[$key]["amountWithTax"] = round(1 * ($price / 100 * (100+$tax)),2);
  1135. if ($this->sSYSTEM->sUSERGROUPDATA["basketdiscount"] && $this->sCheckForDiscount()){
  1136. $discount += ($getArticles[$key]["amountWithTax"]/100*$this->sSYSTEM->sUSERGROUPDATA["basketdiscount"]);
  1137. }
  1138. }
  1139. }
  1140.  
  1141. $getArticles[$key]["amount"] = $quantity * round($price,2);
  1142.  
  1143. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1144.  
  1145. //reset purchaseunit and save the original value in purchaseunitTemp
  1146. if ($getArticles[$key]["purchaseunit"]>0){
  1147. $getArticles[$key]["purchaseunitTemp"] = $getArticles[$key]["purchaseunit"];
  1148. $getArticles[$key]["purchaseunit"] = 1;
  1149. }
  1150.  
  1151. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1152.  
  1153.  
  1154. // If price per unit is not referering to 1, calculate base-price
  1155. // Choose 1000, quantity refers to 500, calculate price / 1000 * 500 as reference
  1156. if ($getArticles[$key]["purchaseunit"]>0){
  1157. $getArticles[$key]["itemInfo"] = $getArticles[$key]["purchaseunit"]." {$getUnitData["description"]} � ".$this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($getArticles[$key]["amount"] / $quantity * $getArticles[$key]["purchaseunit"]);
  1158. $getArticles[$key]["itemInfoArray"]["reference"] = $getArticles[$key]["purchaseunit"];
  1159. $getArticles[$key]["itemInfoArray"]["unit"] = $getUnitData;
  1160. $getArticles[$key]["itemInfoArray"]["price"] = $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($getArticles[$key]["amount"] / $quantity * $getArticles[$key]["purchaseunit"]);
  1161. }
  1162.  
  1163.  
  1164. if ($value["modus"]==2){
  1165. // Gutscheine
  1166. if (!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"]){
  1167. $getArticles[$key]["amountnet"] = $quantity * round($price,2);
  1168. }else {
  1169.  
  1170. $getArticles[$key]["amountnet"] = $quantity * round($netprice,2);
  1171. }
  1172.  
  1173. }else {
  1174. $getArticles[$key]["amountnet"] = $quantity * round($netprice,2);
  1175. }
  1176.  
  1177. $totalAmount += round($getArticles[$key]["amount"],2);
  1178. // Needed if shop is in net-mode
  1179. $totalAmountWithTax += round($getArticles[$key]["amountWithTax"],2);
  1180. // Ignore vouchers and premiums by counting articles
  1181. if (!$getArticles[$key]["modus"]){
  1182. $totalCount++;
  1183. }
  1184.  
  1185. $totalAmountNet += $getArticles[$key]["amountnet"];
  1186.  
  1187. $getArticles[$key]["priceNumeric"] = $getArticles[$key]["price"];
  1188. $getArticles[$key]["price"] = $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($getArticles[$key]["price"]);
  1189. $getArticles[$key]["amount"] = $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($getArticles[$key]["amount"]);
  1190. $getArticles[$key]["amountnet"] = $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($getArticles[$key]["amountnet"]);
  1191.  
  1192. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1193.  
  1194. if (!empty($getArticles[$key]["purchaseunitTemp"])){
  1195. $getArticles[$key]["purchaseunit"] = $getArticles[$key]["purchaseunitTemp"];
  1196. $getArticles[$key]["itemInfo"] = $getArticles[$key]["purchaseunit"]." {$getUnitData["description"]} � ".$this->sSYSTEM->sMODULES['sArticles']->sFormatPrice(str_replace(",",".",$getArticles[$key]["amount"]) / $quantity);
  1197. }
  1198.  
  1199. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1200.  
  1201.  
  1202. if (empty($value["modus"])){
  1203. // Article-Image
  1204. if (!empty($getArticles[$key]["ob_attr1"])){
  1205.  
  1206. $getArticles[$key]["image"] = $this->sSYSTEM->sMODULES['sArticles']->sGetConfiguratorImage($this->sSYSTEM->sMODULES['sArticles']->sGetArticlePictures($getArticles[$key]["articleID"],false,$this->sSYSTEM->sCONFIG['sTHUMBBASKET'],false,true),$getArticles[$key]["ob_attr1"]);
  1207. }else {
  1208. $getArticles[$key]["image"] = $this->sSYSTEM->sMODULES['sArticles']->sGetArticlePictures($getArticles[$key]["articleID"],true,$this->sSYSTEM->sCONFIG['sTHUMBBASKET'],$getArticles[$key]["ordernumber"]);
  1209. }
  1210. }
  1211. // Links to details, basket
  1212. $getArticles[$key]["linkDetails"] = $this->sSYSTEM->sCONFIG['sBASEFILE']."?sViewport=detail&sArticle=".$getArticles[$key]["articleID"];
  1213. if($value["modus"]==2)
  1214. {
  1215. $getArticles[$key]["linkDelete"] = $this->sSYSTEM->sCONFIG['sBASEFILE']."?sViewport=basket&sDelete=voucher";
  1216. }else{
  1217. $getArticles[$key]["linkDelete"] = $this->sSYSTEM->sCONFIG['sBASEFILE']."?sViewport=basket&sDelete=".$getArticles[$key]["id"];
  1218. }
  1219.  
  1220. $getArticles[$key]["linkNote"] = $this->sSYSTEM->sCONFIG['sBASEFILE']."?sViewport=note&sAdd=".$getArticles[$key]["ordernumber"];
  1221.  
  1222. $getArticles[$key] = Enlight()->Events()->filter('Shopware_Modules_Basket_GetBasket_FilterItemEnd', $getArticles[$key], array('subject'=>$this,'getArticles'=>$getArticles));
  1223. }
  1224.  
  1225. if ($totalAmount < 0 || empty($totalCount)) {
  1226. /*
  1227. $deleteBasket = $this->sSYSTEM->sDB_CONNECTION->Execute("
  1228. DELETE FROM s_order_basket WHERE sessionID='".$this->sSYSTEM->sSESSION_ID."'
  1229. ");
  1230. */
  1231. return array();
  1232. }
  1233.  
  1234. // Total-Amount brutto (or netto if shop-mode is to show net-prices)
  1235. $totalAmountNumeric = $totalAmount;
  1236. $totalAmount = $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($totalAmount);
  1237.  
  1238. // Total-Amount brutto (in any case)
  1239. $totalAmountWithTaxNumeric = $totalAmountWithTax;
  1240. $totalAmountWithTax = $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($totalAmountWithTax);
  1241.  
  1242. // Total-Amount netto
  1243. $totalAmountNetNumeric = $totalAmountNet;
  1244.  
  1245. $totalAmountNet = $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($totalAmountNet);
  1246.  
  1247. $result = array("content"=>$getArticles,"Amount"=>$totalAmount,"AmountNet"=>$totalAmountNet,"Quantity"=>$totalCount,"AmountNumeric"=>$totalAmountNumeric,"AmountNetNumeric"=>$totalAmountNetNumeric,"AmountWithTax"=>$totalAmountWithTax,"AmountWithTaxNumeric"=>$totalAmountWithTaxNumeric);
  1248.  
  1249.  
  1250. if (!empty($this->sSYSTEM->_SESSION["sLastArticle"])){ // r302, sth
  1251. $result["sLastActiveArticle"] = array("id"=>$this->sSYSTEM->_SESSION["sLastArticle"],"link"=> $this->sSYSTEM->sCONFIG['sBASEFILE']."?sViewport=detail&sDetails=".$this->sSYSTEM->_SESSION["sLastArticle"]);
  1252. }
  1253.  
  1254. if (!empty($result["content"])){ // r302, sth
  1255.  
  1256. foreach ($result["content"] as $key => $value){
  1257. if(!empty($value['amountWithTax']))
  1258. {
  1259. $t = round(str_replace(",",".",$value['amountWithTax']),2);
  1260. }
  1261. else
  1262. {
  1263. $t = str_replace(",",".",$value["price"]);
  1264. $t = floatval(round($t*$value["quantity"],2));
  1265. }
  1266. if (!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"]){
  1267. $p = floatval($this->sSYSTEM->sMODULES['sArticles']->sRound($this->sSYSTEM->sMODULES['sArticles']->sRound(round($value["netprice"],2)*$value["quantity"])));
  1268. }else {
  1269. $p = floatval($this->sSYSTEM->sMODULES['sArticles']->sRound($this->sSYSTEM->sMODULES['sArticles']->sRound($value["netprice"]*$value["quantity"])));
  1270. }
  1271. $calcDifference = $this->sSYSTEM->sMODULES['sArticles']->sFormatPrice($t - $p);
  1272. $result["content"][$key]["tax"] = $calcDifference;
  1273. }
  1274. }
  1275. $result = Enlight()->Events()->filter('Shopware_Modules_Basket_GetBasket_FilterResult', $result, array('subject'=>$this));
  1276.  
  1277. return $result;
  1278. }else {
  1279. return array();
  1280. }
  1281. }
  1282.  
  1283. /**
  1284. * Add product to bookmarks
  1285. * @param int $articleID
  1286. * @param string $articleName
  1287. * @param string $articleOrdernumber
  1288. * @access public
  1289. * @deprecated
  1290. * @return void
  1291. */
  1292. public function sAddNote($articleID, $articleName, $articleOrdernumber){
  1293. $datum = date("Y-m-d H:i:s");
  1294.  
  1295. if (!empty($this->sSYSTEM->_COOKIE)&&empty($this->sSYSTEM->_COOKIE["sUniqueID"]))
  1296. {
  1297. $this->sSYSTEM->_COOKIE["sUniqueID"] = md5(uniqid(rand()));
  1298. setcookie("sUniqueID", $this->sSYSTEM->_COOKIE["sUniqueID"], Time()+(86400*360), '/');
  1299. }
  1300.  
  1301. // Check if this article is already noted
  1302. $checkForArticle = $this->sSYSTEM->sDB_CONNECTION->GetRow("
  1303. SELECT id FROM s_order_notes WHERE sUniqueID=? AND ordernumber=?
  1304. ",array($this->sSYSTEM->_COOKIE["sUniqueID"],$articleOrdernumber));
  1305.  
  1306. if (!$checkForArticle["id"]){
  1307. $queryNewPrice = $this->sSYSTEM->sDB_CONNECTION->Execute("
  1308. INSERT INTO s_order_notes (sUniqueID, userID,articlename, articleID, ordernumber, datum)
  1309. VALUES (?,?,?,?,?,?)
  1310. ",array(empty($this->sSYSTEM->_COOKIE["sUniqueID"]) ? $this->sSYSTEM->sSESSION_ID : $this->sSYSTEM->_COOKIE["sUniqueID"],$this->sSYSTEM->_SESSION['sUserId'] ?$this->sSYSTEM->_SESSION['sUserId'] : "0" ,$articleName,$articleID,$articleOrdernumber,$datum));
  1311.  
  1312. if (!$queryNewPrice){
  1313. $this->sSYSTEM->E_CORE_WARNING ("sBasket##sAddNote##01","Error in SQL-query");
  1314. return false;
  1315. }
  1316. }
  1317. return true;
  1318. }
  1319.  
  1320. /**
  1321. * Get all products current on bookmark
  1322. * @deprecated
  1323. * @return array
  1324. */
  1325. public function sGetNotes()
  1326. {
  1327. $getArticles = $this->sSYSTEM->sDB_CONNECTION->GetAll('
  1328. SELECT n.* FROM s_order_notes n, s_articles a
  1329. WHERE (sUniqueID=? OR (userID!=0 AND userID=?))
  1330. AND a.id = n.articleID AND a.active = 1
  1331. ORDER BY n.datum DESC
  1332. ', array(
  1333. empty($this->sSYSTEM->_COOKIE['sUniqueID']) ? $this->sSYSTEM->sSESSION_ID : $this->sSYSTEM->_COOKIE['sUniqueID'],
  1334. isset($this->sSYSTEM->_SESSION['sUserId']) ? $this->sSYSTEM->_SESSION['sUserId'] : 0
  1335. ));
  1336.  
  1337. if(empty($getArticles)) {
  1338. return $getArticles;
  1339. }
  1340.  
  1341. // Reformating data, add additional datafields to array
  1342. foreach ($getArticles as $key => $value){
  1343. // Article-Image
  1344. $getArticles[$key] = $this->sSYSTEM->sMODULES['sArticles']->sGetPromotionById("fix", 0, (int) $value["articleID"]);
  1345. if(empty($getArticles[$key])) {
  1346. $this->sDeleteNote($value["id"]);
  1347. unset($getArticles[$key]);
  1348. continue;
  1349. }
  1350. $getArticles[$key]["articlename"] = $getArticles[$key]["articleName"];
  1351. $getArticles[$key]["image"] = $this->sSYSTEM->sMODULES['sArticles']->getArticleListingCover($value["articleID"], Shopware()->Config()->get('forceArticleMainImageInListing'));
  1352. // Links to details, basket
  1353. $getArticles[$key]["id"] = $value["id"];
  1354. $getArticles[$key]["linkBasket"] = $this->sSYSTEM->sCONFIG['sBASEFILE']."?sViewport=basket&sAdd=".$value["ordernumber"];
  1355. $getArticles[$key]["linkDelete"] = $this->sSYSTEM->sCONFIG['sBASEFILE']."?sViewport=note&sDelete=".$value["id"];
  1356. $getArticles[$key]["datum_add"] = $value["datum"];
  1357. }
  1358. return $getArticles;
  1359. }
  1360.  
  1361. /**
  1362. * Returns the number of notepad entries
  1363. * @deprecated
  1364. * @return int
  1365. */
  1366. public function sCountNotes()
  1367. {
  1368. $count = (int) $this->sSYSTEM->sDB_CONNECTION->GetOne('
  1369. SELECT COUNT(*) FROM s_order_notes n, s_articles a
  1370. WHERE (sUniqueID=? OR (userID!=0 AND userID = ?))
  1371. AND a.id = n.articleID AND a.active = 1
  1372. ', array(
  1373. empty($this->sSYSTEM->_COOKIE['sUniqueID']) ? $this->sSYSTEM->sSESSION_ID : $this->sSYSTEM->_COOKIE['sUniqueID'],
  1374. isset($this->sSYSTEM->_SESSION['sUserId']) ? $this->sSYSTEM->_SESSION['sUserId'] : 0
  1375. ));
  1376. return $count;
  1377. }
  1378.  
  1379.  
  1380.  
  1381. /**
  1382. * Update quantity / price of a certain cart position
  1383. * @param int $id - s_order_basket.id
  1384. * @param int $quantity - Neue Menge
  1385. * @access public
  1386. * @deprecated
  1387. * @return boolean
  1388. */
  1389. public function sUpdateArticle ($id,$quantity){
  1390. // Int values should be int values ;)
  1391. $quantity = intval($quantity);
  1392. $id = intval($id);
  1393.  
  1394. if (Enlight()->Events()->notifyUntil('Shopware_Modules_Basket_UpdateArticle_Start', array('subject'=>$this,'id'=>$id,"quantity"=>$quantity))){
  1395. return false;
  1396. }
  1397.  
  1398. if (empty($id)) return false;
  1399.  
  1400. // Query to get minimum surcharge
  1401. $queryAdditionalInfo = $this->sSYSTEM->sDB_CONNECTION->GetRow("
  1402. SELECT s_articles_details.minpurchase, s_articles_details.purchasesteps, s_articles_details.maxpurchase, s_articles_details.purchaseunit, pricegroupID,pricegroupActive, s_order_basket.ordernumber, s_order_basket.articleID
  1403. FROM s_articles, s_order_basket, s_articles_details
  1404.  
  1405. WHERE s_order_basket.articleID = s_articles.id
  1406. AND s_order_basket.ordernumber = s_articles_details.ordernumber
  1407. AND s_order_basket.id=?
  1408. AND
  1409. s_order_basket.sessionID=?
  1410. ",array($id,$this->sSYSTEM->sSESSION_ID));
  1411.  
  1412. // Check if quantity matches minimum-purchase
  1413. if (!$queryAdditionalInfo["minpurchase"]){
  1414. $queryAdditionalInfo["minpurchase"] = 1;
  1415. }
  1416.  
  1417. if ($quantity<$queryAdditionalInfo["minpurchase"]){
  1418. $quantity = $queryAdditionalInfo["minpurchase"];
  1419. }
  1420.  
  1421. // Check if quantity matches the step-requirements
  1422. if (!$queryAdditionalInfo["purchasesteps"]){
  1423. $queryAdditionalInfo["purchasesteps"] = 1;
  1424. }
  1425.  
  1426. if (($quantity/$queryAdditionalInfo["purchasesteps"])!=intval($quantity / $queryAdditionalInfo["purchasesteps"])){
  1427. $quantity = intval($quantity / $queryAdditionalInfo["purchasesteps"])*$queryAdditionalInfo["purchasesteps"];
  1428. }
  1429.  
  1430. if(empty($queryAdditionalInfo["maxpurchase"]) && !empty($this->sSYSTEM->sCONFIG['sMAXPURCHASE'])){
  1431. $queryAdditionalInfo["maxpurchase"] = $this->sSYSTEM->sCONFIG['sMAXPURCHASE'];
  1432. }
  1433.  
  1434. // Check if quantity matches max-purchase
  1435. if ($quantity>$queryAdditionalInfo["maxpurchase"] && !empty($queryAdditionalInfo["maxpurchase"]))
  1436. {
  1437. $quantity = $queryAdditionalInfo["maxpurchase"];
  1438. }
  1439.  
  1440.  
  1441. if (!$this->sSYSTEM->sSESSION_ID || !$id) {
  1442. return false;
  1443. }
  1444.  
  1445. /*
  1446. SW 2.1 Pricegroups
  1447. */
  1448. if ($queryAdditionalInfo["pricegroupActive"]){
  1449. $quantitySQL = "AND s_articles_prices.from = 1 LIMIT 1";
  1450. }else {
  1451. $quantitySQL = "AND s_articles_prices.from <= $quantity AND (s_articles_prices.to >= $quantity OR s_articles_prices.to=0)";
  1452. }
  1453.  
  1454. // Get the ordernumber
  1455. $sql = "SELECT s_articles_prices.price AS price,taxID,s_core_tax.tax AS tax,tax_rate,s_articles_details.id AS articleDetailsID, s_articles_details.articleID, s_order_basket.config, s_order_basket.ordernumber FROM s_articles_details, s_articles_prices, s_order_basket,
  1456. s_articles, s_core_tax
  1457. WHERE s_order_basket.id=$id AND s_order_basket.sessionID='".$this->sSYSTEM->sSESSION_ID."'
  1458. AND s_order_basket.ordernumber = s_articles_details.ordernumber
  1459. AND s_articles_details.id=s_articles_prices.articledetailsID
  1460. AND s_articles_details.articleID = s_articles.id
  1461. AND s_articles.taxID = s_core_tax.id
  1462. AND s_articles_prices.pricegroup='".$this->sSYSTEM->sUSERGROUP."'
  1463. $quantitySQL
  1464. ";
  1465.  
  1466. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1467.  
  1468. if (!empty($queryAdditionalInfo["purchaseunit"]))
  1469. {
  1470. $queryAdditionalInfo["purchaseunit"] = 1;
  1471. }
  1472.  
  1473. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1474.  
  1475.  
  1476. $queryNewPrice = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql);
  1477.  
  1478. /*
  1479. SW 2.1 - Load prices from defaultgroup if no own prices defined
  1480. */
  1481. if (!$queryNewPrice["price"]){
  1482. // In the case no price is available for this customergroup, use price of default customergroup
  1483. $sql = "SELECT s_articles_prices.price AS price,taxID,s_core_tax.tax AS tax,s_articles_details.id AS articleDetailsID, s_articles_details.articleID, s_order_basket.config, s_order_basket.ordernumber FROM s_articles_details, s_articles_prices, s_order_basket,
  1484. s_articles, s_core_tax
  1485. WHERE s_order_basket.id=$id AND s_order_basket.sessionID='".$this->sSYSTEM->sSESSION_ID."'
  1486. AND s_order_basket.ordernumber = s_articles_details.ordernumber
  1487. AND s_articles_details.id=s_articles_prices.articledetailsID
  1488. AND s_articles_details.articleID = s_articles.id
  1489. AND s_articles.taxID = s_core_tax.id
  1490. AND s_articles_prices.pricegroup='EK'
  1491. $quantitySQL
  1492. ";
  1493. $queryNewPrice = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql);
  1494. }
  1495.  
  1496. if (empty($queryNewPrice["price"])&&empty($queryNewPrice["config"])){
  1497. // If no price is set for default customergroup, delete article from basket
  1498. $this->sDeleteArticle($id);
  1499. return false;
  1500. }
  1501.  
  1502. // Determinate tax-rate for this cart position
  1503. $taxRate = $this->sSYSTEM->sMODULES['sArticles']->getTaxRateByConditions($queryNewPrice["taxID"]);
  1504.  
  1505. $netprice = $queryNewPrice["price"];
  1506.  
  1507. /*
  1508. Recalculate Price if purchaseunit is set
  1509. */
  1510. $brutto = $this->sSYSTEM->sMODULES['sArticles']->sCalculatingPriceNum($netprice,$queryNewPrice["tax"],false,false,$queryNewPrice["taxID"],false, $queryNewPrice);
  1511.  
  1512. // Check if tax-free
  1513. if (($this->sSYSTEM->sCONFIG['sARTICLESOUTPUTNETTO'] && !$this->sSYSTEM->sUSERGROUPDATA["tax"]) || (!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"])){
  1514. // Brutto is equal to net - price
  1515. $netprice = round($brutto,2);
  1516.  
  1517. }else {
  1518. // Round to right value, if no purchase-unit is set
  1519. if ($queryAdditionalInfo["purchaseunit"] == 1){
  1520. $brutto = round($brutto, 2);
  1521. }
  1522. // Consider global discount for net price
  1523. $netprice = $brutto / (100 + $taxRate) * 100;
  1524. }
  1525.  
  1526. // Recalculate price per item, if purchase-unit is set
  1527. if ($queryAdditionalInfo["purchaseunit"]>0){
  1528. $brutto = $brutto / $queryAdditionalInfo["purchaseunit"];
  1529. $netprice = $netprice / $queryAdditionalInfo["purchaseunit"];
  1530. }
  1531.  
  1532. if (empty($this->sSYSTEM->sCurrency["factor"])) $this->sSYSTEM->sCurrency["factor"] = 1;
  1533.  
  1534. if ($queryAdditionalInfo["pricegroupActive"]){
  1535.  
  1536. $brutto = $this->sSYSTEM->sMODULES['sArticles']->sGetPricegroupDiscount($this->sSYSTEM->sUSERGROUP,$queryAdditionalInfo["pricegroupID"],$brutto,$quantity,false);
  1537. $brutto = $this->sSYSTEM->sMODULES['sArticles']->sRound($brutto);
  1538. if (($this->sSYSTEM->sCONFIG['sARTICLESOUTPUTNETTO'] && !$this->sSYSTEM->sUSERGROUPDATA["tax"]) || (!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"])){
  1539. $netprice = $this->sSYSTEM->sMODULES['sArticles']->sRound($this->sSYSTEM->sMODULES['sArticles']->sGetPricegroupDiscount($this->sSYSTEM->sUSERGROUP,$queryAdditionalInfo["pricegroupID"],$netprice,$quantity,false));
  1540.  
  1541. }else {
  1542. $netprice = $brutto / (100 + $taxRate)* 100;//$this->sSYSTEM->sMODULES['sArticles']->sGetPricegroupDiscount($this->sSYSTEM->sUSERGROUP,$queryAdditionalInfo["pricegroupID"],$netprice,$quantity,false);
  1543. $netprice = number_format($netprice,3,".","");
  1544. }
  1545. }
  1546.  
  1547. $sql = "
  1548. UPDATE s_order_basket SET quantity=?, price=?, netprice=?, currencyFactor=?,
  1549. tax_rate = ?
  1550. WHERE id=? AND sessionID=? AND modus=0
  1551. ";
  1552. $sql = Enlight()->Events()->filter('Shopware_Modules_Basket_UpdateArticle_FilterSqlDefault',$sql, array('subject'=>$this,'id'=>$id,"quantity"=>$quantity,"price"=>$brutto,"netprice"=>$netprice,"currencyFactor"=>$this->sSYSTEM->sCurrency["factor"]));
  1553.  
  1554. if ($taxRate === false){
  1555. $taxRate = $brutto == $netprice ? 0.00 : $queryNewPrice["tax"];
  1556. }
  1557.  
  1558. $params = array(
  1559. $quantity,
  1560. $brutto,
  1561. $netprice,
  1562. $this->sSYSTEM->sCurrency["factor"],
  1563. $taxRate,
  1564. $id,
  1565. $this->sSYSTEM->sSESSION_ID
  1566. );
  1567.  
  1568. $update = $this->sSYSTEM->sDB_CONNECTION->Execute($sql,$params);
  1569.  
  1570. $this->sUpdateVoucher();
  1571.  
  1572. if (!$update || !$queryNewPrice){
  1573. $this->sSYSTEM->E_CORE_WARNING("Basket Update ##01","Could not update quantity".$sql);
  1574. }
  1575. return;
  1576. }
  1577.  
  1578. /**
  1579. * Check if any esd article is in cart
  1580. * @access public
  1581. * @deprecated
  1582. * @return void
  1583. */
  1584.  
  1585. public function sCheckForESD(){
  1586. $sql = "SELECT id FROM s_order_basket WHERE sessionID=? AND esdarticle=1 LIMIT 1
  1587. ";
  1588.  
  1589. $getArticles = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql,array($this->sSYSTEM->sSESSION_ID));
  1590.  
  1591. if ($getArticles["id"]){
  1592. return true;
  1593. }else {
  1594. return false;
  1595. }
  1596.  
  1597. }
  1598.  
  1599. /**
  1600. * Truncate cart
  1601. * @access public
  1602. * @deprecated
  1603. * @return void
  1604. */
  1605. public function sDeleteBasket (){
  1606. if (empty($this->sSYSTEM->sSESSION_ID)) return false;
  1607. $sql = "
  1608. DELETE FROM s_order_basket WHERE sessionID=?";
  1609. $delete = $this->sSYSTEM->sDB_CONNECTION->Execute($sql,array($this->sSYSTEM->sSESSION_ID));
  1610. }
  1611.  
  1612.  
  1613. /**
  1614. * Delete a certain position from cart
  1615. * @param int $id s_order_basket.id
  1616. * @access public
  1617. * @deprecated
  1618. * @return void
  1619. */
  1620. public function sDeleteArticle ($id){
  1621. $id = (int)$id;
  1622. $modus = $this->sSYSTEM->sDB_CONNECTION->GetOne('SELECT `modus` FROM `s_order_basket` WHERE `id`=?', array($id));
  1623.  
  1624. if ($id && $id != "voucher"){
  1625. $sql = "
  1626. DELETE FROM s_order_basket WHERE sessionID=? AND id=?
  1627. ";
  1628. $delete = $this->sSYSTEM->sDB_CONNECTION->Execute($sql,array($this->sSYSTEM->sSESSION_ID,$id));
  1629. if (!$delete){
  1630. $this->sSYSTEM->E_CORE_WARNING("Basket Delete ##01","Could not delete item ($sql)");
  1631. }
  1632. if(empty($modus))
  1633. {
  1634. $this->sUpdateVoucher();
  1635. }
  1636. return;
  1637. } else {
  1638. return;
  1639. }
  1640. }
  1641.  
  1642. /**
  1643. * Delete a certain position from note
  1644. * @param int $id s_order_notes.id
  1645. * @access public
  1646. * @deprecated
  1647. * @return void
  1648. */
  1649. public function sDeleteNote ($id){
  1650. $id = (int)$id;
  1651.  
  1652. if (!empty($id)){
  1653. $sql = "
  1654. DELETE FROM s_order_notes WHERE (sUniqueID=? OR (userID = ? AND userID != 0)) AND id=?
  1655. ";
  1656. $delete = $this->sSYSTEM->sDB_CONNECTION->Execute($sql,array($this->sSYSTEM->_COOKIE["sUniqueID"],$this->sSYSTEM->_SESSION['sUserId'],$id));
  1657. if (!$delete){
  1658. $this->sSYSTEM->E_CORE_WARNING("Basket sDeleteNote ##01","Could not delete item ($sql)");
  1659. }
  1660. return true;
  1661. } else {
  1662. return false;
  1663. }
  1664. }
  1665. /**
  1666. * Add product to cart
  1667. * @param int $id ordernumber (s_order_details.ordernumber)
  1668. * @param int $quantity amount
  1669. * @access public
  1670. * @deprecated
  1671. * @return void
  1672. */
  1673. public function sAddArticle ($id, $quantity=1)
  1674. {
  1675. if ($this->sSYSTEM->sBotSession) return false;
  1676. if (empty($this->sSYSTEM->sSESSION_ID)) return false;
  1677.  
  1678.  
  1679. $quantity = (empty($quantity)||!is_numeric($quantity)) ? 1 : (int) $quantity;
  1680. if ($quantity<=0) $quantity = 1;
  1681.  
  1682.  
  1683. if (Enlight()->Events()->notifyUntil('Shopware_Modules_Basket_AddArticle_Start', array('subject'=>$this,'id'=>$id,"quantity"=>$quantity))){
  1684. return false;
  1685. }
  1686.  
  1687. $sql = "
  1688. SELECT s_articles.id AS articleID, name AS articleName, taxID, additionaltext, s_articles_details.shippingfree,laststock,instock, s_articles_details.id as articledetailsID, ordernumber
  1689. FROM s_articles, s_articles_details
  1690. WHERE s_articles_details.ordernumber=?
  1691. AND s_articles_details.articleID=s_articles.id
  1692. AND s_articles.active = 1
  1693. AND (
  1694. SELECT articleID
  1695. FROM s_articles_avoid_customergroups
  1696. WHERE articleID = s_articles.id AND customergroupID = ".$this->sSYSTEM->sUSERGROUPDATA["id"]."
  1697. ) IS NULL
  1698. ";
  1699. $getArticle = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql,array($id));
  1700.  
  1701. $getName = $this->sSYSTEM->sMODULES["sArticles"]->sGetArticleNameByOrderNumber($getArticle["ordernumber"],true);
  1702.  
  1703. if (!empty($getName)){
  1704. $getArticle["articleName"] = $getName["articleName"];
  1705. $getArticle["additionaltext"] = $getName["additionaltext"];
  1706. }
  1707.  
  1708. if (!count($getArticle)){
  1709.  
  1710. //$this->sSYSTEM->E_CORE_WARNING ("BASKET-INSERT #00","Article $id not found");
  1711. //unset($this->sSYSTEM->_GET["sAdd"]);
  1712. return false;
  1713. }else {
  1714.  
  1715. // Check if article is already in basket
  1716. $sql = "
  1717. SELECT id, quantity FROM s_order_basket WHERE articleID=? AND sessionID=? AND
  1718. ordernumber=?";
  1719.  
  1720. $chkBasketForArticle = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql,array($getArticle["articleID"],$this->sSYSTEM->sSESSION_ID,$getArticle["ordernumber"]));
  1721.  
  1722. // Shopware 3.5.0 / sth / laststock - instock check
  1723. if (!empty($chkBasketForArticle["id"])){
  1724.  
  1725. if ($getArticle["laststock"] == true && $getArticle["instock"] < ($chkBasketForArticle["quantity"] + $quantity) ){
  1726. $quantity -= $chkBasketForArticle["quantity"];
  1727.  
  1728. }
  1729. }else {
  1730. if ($getArticle["laststock"] == true && $getArticle["instock"] <= $quantity){
  1731. $quantity = $getArticle["instock"];
  1732. if ($quantity <= 0){
  1733. return;
  1734. }
  1735. }
  1736. }
  1737. // --
  1738.  
  1739. $insertTime = date("Y-m-d H:i:s");
  1740.  
  1741. if ($chkBasketForArticle&&empty($sUpPriceValues)){
  1742.  
  1743. // Article is already in basket, update quantity
  1744. $quantity += $chkBasketForArticle["quantity"];
  1745.  
  1746. $this->sUpdateArticle($chkBasketForArticle["id"],$quantity);
  1747. return $chkBasketForArticle["id"];
  1748. }
  1749. else {
  1750.  
  1751. // Read price from default-price-table
  1752. $sql = "SELECT price,s_core_tax.tax AS tax FROM s_articles_prices,s_core_tax WHERE
  1753. s_articles_prices.pricegroup=?
  1754. AND s_articles_prices.articledetailsID=?
  1755. AND s_core_tax.id=?
  1756. ";
  1757. $getPrice = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql,array($this->sSYSTEM->sUSERGROUP,$getArticle["articledetailsID"],$getArticle["taxID"]));
  1758.  
  1759. if (empty($getPrice["price"])){
  1760. $sql = "SELECT price,s_core_tax.tax AS tax FROM s_articles_prices,s_core_tax WHERE
  1761. s_articles_prices.pricegroup='EK'
  1762. AND s_articles_prices.articledetailsID=?
  1763. AND s_core_tax.id=?
  1764. ";
  1765. $getPrice = $this->sSYSTEM->sDB_CONNECTION->GetRow($sql,array($getArticle["articledetailsID"],$getArticle["taxID"]));
  1766. }
  1767.  
  1768.  
  1769. if (!$getPrice["price"] && !$getArticle["free"]){
  1770. // No price could acquired
  1771. $this->sSYSTEM->E_CORE_WARNING ("BASKET-INSERT #01","No price acquired");
  1772. return;
  1773. }else {
  1774.  
  1775. // If configuration article
  1776. if (($this->sSYSTEM->sCONFIG['sARTICLESOUTPUTNETTO'] && !$this->sSYSTEM->sUSERGROUPDATA["tax"]) || (!$this->sSYSTEM->sUSERGROUPDATA["tax"] && $this->sSYSTEM->sUSERGROUPDATA["id"])){
  1777. // If netto set both values to net-price
  1778. $getPrice["price"] = $this->sSYSTEM->sMODULES['sArticles']->sCalculatingPriceNum($getPrice["price"],$getPrice["tax"],false,false,$getArticle["taxID"],false,$getArticle);
  1779. $getPrice["netprice"] = $getPrice["price"];
  1780. }else {
  1781. // If brutto, save net
  1782. $getPrice["netprice"] = $getPrice["price"];
  1783. $getPrice["price"] = $this->sSYSTEM->sMODULES['sArticles']->sCalculatingPriceNum($getPrice["price"],$getPrice["tax"],false,false,$getArticle["taxID"],false, $getArticle);
  1784. }
  1785. // For variants, extend the article-name
  1786. if ($getArticle["additionaltext"]){
  1787. $getArticle["articleName"].= " ".$getArticle["additionaltext"];
  1788. }
  1789.  
  1790. if (!$getArticle["shippingfree"]) $getArticle["shippingfree"] = "0";
  1791.  
  1792. // Check if article is an esd-article
  1793. // - add flag to basket
  1794. $sqlGetEsd = "
  1795. SELECT s_articles_esd.id AS id, serials FROM s_articles_esd,s_articles_details WHERE s_articles_esd.articleID=?
  1796. AND s_articles_esd.articledetailsID=s_articles_details.id AND s_articles_details.ordernumber=?
  1797. ";
  1798. $getEsd = $this->sSYSTEM->sDB_CONNECTION->GetRow($sqlGetEsd,array($getArticle["articleID"],$getArticle["ordernumber"]));
  1799. if ($getEsd["id"]){
  1800. $sEsd = "1";
  1801. }else {
  1802. $sEsd = "0";
  1803. }
  1804.  
  1805. $quantity = (int) $quantity;
  1806. $sql = "
  1807. INSERT INTO s_order_basket (id,sessionID,userID,articlename,articleID,
  1808. ordernumber, shippingfree, quantity, price, netprice, datum, esdarticle, partnerID, config)
  1809. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
  1810. ";
  1811.  
  1812. $params = array(
  1813. '',
  1814. (string) $this->sSYSTEM->sSESSION_ID,
  1815. (string) $this->sSYSTEM->_SESSION['sUserId'],
  1816. $getArticle["articleName"],
  1817. $getArticle["articleID"],
  1818. (string) $getArticle["ordernumber"],
  1819. $getArticle["shippingfree"],
  1820. $quantity,
  1821. $getPrice["price"],
  1822. $getPrice["netprice"],
  1823. (string) $insertTime,
  1824. $sEsd,
  1825. (string) $this->sSYSTEM->_SESSION["sPartner"],
  1826. (empty($sUpPriceValues) ? "" : serialize($sUpPriceValues))
  1827. );
  1828.  
  1829. $sql = Enlight()->Events()->filter('Shopware_Modules_Basket_AddArticle_FilterSql',$sql, array('subject'=>$this,"article"=>$getArticle,"price"=>$getPrice,"esd"=>$sEsd,"quantity"=>$quantity,"partner"=>$this->sSYSTEM->_SESSION["sPartner"]));
  1830.  
  1831. $rs = $this->sSYSTEM->sDB_CONNECTION->Execute($sql, $params);
  1832.  
  1833. if (!$rs){
  1834. $this->sSYSTEM->E_CORE_WARNING ("BASKET-INSERT #02","SQL-Error".$sql);
  1835. }
  1836. $insertId = $this->sSYSTEM->sDB_CONNECTION->Insert_ID();
  1837.  
  1838. $sql = "INSERT INTO s_order_basket_attributes (basketID, attribute1) VALUES (". $insertId .", ".$this->sSYSTEM->sDB_CONNECTION->qstr(implode($pictureRelations,"$$")).")";
  1839. $this->sSYSTEM->sDB_CONNECTION->Execute($sql);
  1840.  
  1841. $this->sUpdateArticle($insertId,$quantity);
  1842.  
  1843. } // If - Price was found
  1844. } // If - Article is not in basket
  1845. } // If - Article was found
  1846.  
  1847. return $insertId;
  1848. }
  1849.  
  1850. /**
  1851. * Refresh basket after login / currency change
  1852. * @deprecated
  1853. */
  1854. public function sRefreshBasket()
  1855. {
  1856. $session = Shopware()->Session();
  1857. $admin = Shopware()->Modules()->Admin();
  1858.  
  1859. // Update basket data
  1860. $admin->sGetUserData();
  1861. $this->sGetBasket();
  1862. $admin->sGetShippingcosts();
  1863.  
  1864. // Update basket data in session
  1865. $session->sBasketCurrency = Shopware()->Shop()->getCurrency()->getId();
  1866. $session->sBasketQuantity = $this->sCountBasket();
  1867. $amount = $this->sGetAmount();
  1868. $session->sBasketAmount = empty($amount) ? 0 : array_shift($amount);
  1869. }
  1870. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement