function tsv_ClearTplfromLabels($tpl) { global $tsvshop; preg_match_all('/(<!--\\/(.*?)-->)/', $tpl, $out); $syslabels = explode(",", $tsvshop['syslabels']); if (!empty($tpl) && is_array($out[2]) && is_array($syslabels)) { foreach ($out[2] as $addon) { if (!tsv_AddonIsOn($addon) && !in_array($addon, $syslabels)) { $tpl = str_replace(getStr($tpl, '<!--' . $addon . '-->', '<!--/' . $addon . '-->'), "", $tpl); } } } return $tpl; }
function tsv_display_cart($cache, $act = "basket") { global $modx, $session, $tsvshop, $shop_lang, $folders, $tables; //$session = session($cache); $total = 0; $items = 0; $output = ""; $tabletmp = ""; $table = ""; $itemstmp = ""; $sub = 0; $tot = 0; $disc_size = 0; $disc = 0; $piece = array(); $addons = array(); if (!act) { $act == "basket"; } if ($tsvshop['debug']) { $output .= print_r($_SESSION[$session]); } $count = sizeof($_SESSION[$session]['orders']); if ($act == "basket") { $tvar = "ct"; $chunk = $tsvshop['tplcart']; } else { $tvar = "ch"; $chunk = $tsvshop['tplcheckout']; $divajax = '<div id="checkout_table">'; } if (empty($count)) { $tvar = "cte"; $chunk = $tsvshop['tplcartempty']; } $tpl = $cache->cache($tvar, 'tsvshop'); if (!$tpl) { if (!($tpl = getTpl($chunk))) { exit(""); } else { $cache->cache($tvar, 'tsvshop', $tpl); } } // плагин TSVshopOnTplCartPrerender $evt = $modx->invokeEvent("TSVshopOnTplCartPrerender", array("tpl" => $tpl)); if (is_array($evt) && !empty($evt[0])) { $tpl = $evt[0]; } // --- $tpl = str_replace("[+shop.basket.monetary+]", $tsvshop['MonetarySymbol'], $tpl); $tpl = str_replace("[+shop.basket.checkurl+]", $tsvshop['checkurl'], $tpl); $tpl = str_replace("[+shop.basket.selfurl+]", $tsvshop['selfurl'], $tpl); // создаем метки для корзины // создаем метки аддона Sales (используются в чанках Shop_Cart и Shop_Checkout) $piece['head'] = getStr($tpl, '<thead>', '</thead>'); $syslabels = explode(",", $tsvshop['syslabels']); foreach ($syslabels as $folder) { $piece[$folder] = getStr($tpl, '<!--' . $folder . '-->', '<!--/' . $folder . '-->'); } // создаем метки аддонов (используются аддонами) foreach ($folders as $folder) { if (tsv_AddonIsOn($folder)) { $piece[$folder] = getStr($tpl, '<!--' . $folder . '-->', '<!--/' . $folder . '-->'); } } if (empty($count)) { //если корзина пуста if ($act == "checkout") { //$modx->sendRedirect($tsvshop['basketurl'],0,'REDIRECT_HEADER'); } } else { for ($i = $count - 1; $i >= 0; $i--) { //$tabletmp = $noempty; // было $tabletmp = $piece['noempty']; $price = tsv_CalcPrice($_SESSION[$session]['orders'][$i]['price'], $_SESSION[$session]['orders'][$i]['qty'], $_SESSION[$session]['orders'][$i]['opt']); $summa = tsv_CalcPrice($_SESSION[$session]['orders'][$i]['price'], $_SESSION[$session]['orders'][$i]['qty'], $_SESSION[$session]['orders'][$i]['opt']) * $_SESSION[$session]['orders'][$i]['qty']; $sub = $sub + $summa; $items = $items + $_SESSION[$session]['orders'][$i]['qty']; //---заполняем шаблон товарами // v 5.0.1 заменяем плейсхолдеры значениями foreach ($_SESSION[$session]['orders'][$i] as $key => $val) { switch ($key) { case 'qty': $tabletmp = str_replace('[+shop.basket.quantity+]', $val, $tabletmp); break; case 'icon': $tabletmp = str_replace('[+shop.basket.iconpath+]', $val, $tabletmp); break; case 'price': $tabletmp = str_replace('[+shop.basket.price+]', $price, $tabletmp); break; case 'url': $url = $tsvshop['TypeCat'] == 'docs' || empty($tsvshop['TypeCat']) ? $modx->makeUrl($val) : "&tovar=" . $val; $tabletmp = str_replace('[+shop.basket.link+]', $url, $tabletmp); //$tabletmp = str_replace('[+shop.basket.id+]', $val, $tabletmp); break; default: $tabletmp = str_replace('[+shop.basket.' . $key . '+]', $val, $tabletmp); break; } } $tabletmp = str_replace('[+shop.basket.qinput+]', '<input type="text" name="q" size="3" class="nopinput" value="' . $_SESSION[$session]['orders'][$i]['qty'] . '" onkeypress="return testKey(event)" onChange="ChangeQuantity(\'' . $i . '\', this.value);">', $tabletmp); $tabletmp = str_replace('[+shop.basket.qatributs+]', 'name="q" value="' . $_SESSION[$session]['orders'][$i]['qty'] . '" onkeypress="return testKey(event)" onChange="ChangeQuantity(\'' . $i . '\', this.value);"', $tabletmp); $tabletmp = str_replace('[+shop.basket.summa+]', $summa, $tabletmp); $tabletmp = str_replace('[+shop.basket.num+]', $i, $tabletmp); $tabletmp = str_replace('[+shop.basket.delatributs+]', 'onClick="RemoveFromCart(\'' . $i . '\'); return false"', $tabletmp); // -------------------------------- $table .= $tabletmp; } $tpl = str_replace($piece['noempty'], $table, $tpl); $tpl = str_replace($piece['empty'], "", $tpl); // ------ Проверяем переменные для итоговой суммы //$tsvshop['shipping'] = ($tsvshop['addons_shipping_active']=="no" || empty($tsvshop['addons_shipping_active'])) ? 0 : $tsvshop['shipping']; if ($tsvshop['addons_shipping_active'] == "no" || empty($tsvshop['addons_shipping_active'])) { $tsvshop['shipping'] = 0; $tsvshop['shipid'] = 0; $tsvshop['shiptype'] = ''; } if ($tsvshop['addons_discount_active'] == "no" || empty($tsvshop['addons_discount_active'])) { $tsvshop['discountsize'] = $tsvshop['discount'] = 0; $tsvshop['discountnum'] = $tsvshop['discounttype'] = ''; } if ($tsvshop['addons_tax_active'] == "no" || empty($tsvshop['addons_tax_active'])) { $tsvshop['Tax'] = $tsvshop['TaxRate'] = 0; $tsvshop['TaxType'] = $tsvshop['TaxName'] = ''; } // ########################## Подсчет подитога корзины ########################## // // Подитог $evt = $modx->invokeEvent("TSVshopOnGetSubtotal", array("subtotal" => $sub)); if (is_array($evt) && !empty($evt[0])) { $sub = $evt[0]; } $tpl = str_replace("[+shop.basket.subtotal+]", $sub, $tpl); $_SESSION[$session]['result']['subtotal'] = $sub; //тут вставляем Actions для корзины foreach ($folders as $folder) { if ($folder != "." && $folder != "..") { $file = TSVSHOP_PATH . "addons/" . $folder . '/actions/action.inc.php'; if (file_exists($file) && $tsvshop['addons_' . $folder . '_active'] == "yes") { require_once $file; } } } // ---- тут на будущее ------------ // ------ Налог -------------------------------------------------- // Название налога, напр. ПДВ // Процентный или фиксированный // Размер скидки //$tsvshop['TaxRate'] = ($tsvshop['DisplayTaxRow']=="false" || empty($tsvshop['DisplayTaxRow'])) ? 0 : $tsvshop['TaxRate']; //$tpl = ($tsvshop['DisplayTaxRow']=="true" && !empty($piece['tax'])) ? str_replace("[+shop.basket.tax+]", $tsvshop['TaxRate'], $tpl) : str_replace($piece['tax'], "", $tpl); //$_SESSION[$session]['result']['nalog'] = $tsvshop['TaxRate']; // ------ Скидка правилами ---------------------------------------- // приплюсовываем скидки в одну // ----------------------------------------------------------------- // -------------------------- Подсчитываем итог -------------------- $tot = $sub - $tsvshop['discountsize'] + (floatval($tsvshop['TaxRate']) + floatval($tsvshop['shipping'])); $tpl = str_replace("[+shop.basket.total+]", $tot, $tpl); $_SESSION[$session]['result']['total'] = $tot; $_SESSION[$session]['result']['count'] = $count; //добавлено с v5.3 ---------------------------------------------------- //определяем переменную topay - сумма к оплате //по умолчанию она равна сумме всего заказа //но ее можно переопределить. $_SESSION[$session]['result']['topay'] = $_SESSION[$session]['result']['total']; // Плагин TSVshopOnBeforeUserFormInit $evt = $modx->invokeEvent("TSVshopOnBeforeUserFormInit", array("tpl" => $tpl)); if (is_array($evt) && !empty($evt[0])) { $tpl = $evt[0]; } if (!empty($_SESSION[$session]['result']['count']) && _filter($_REQUEST['act']) != 'recalc') { $tsvshop['MinimumOrder'] = empty($tsvshop['MinimumOrder']) ? 0 : $tsvshop['MinimumOrder']; if ($tot < $tsvshop['MinimumOrder']) { $tpl = str_replace("[+shop.basket.userform+]", notice(str_replace('%minsum%', $tsvshop['MinimumOrder'] . " " . $tsvshop['MonetarySymbol'], $shop_lang['strMinimumOrder']), 'error'), $tpl); } else { $tpl = str_replace("[+shop.basket.userform+]", '</div>' . $modx->runSnippet("eForm", array('tpl' => $tsvshop['tpluserform'], 'formid' => 'TSVCheckoutForm', 'eformOnBeforeFormParse' => 'tsv_ParseUserForm', 'eFormOnBeforeMailSent' => 'tsv_Finish', 'allowhtml' => '1', 'noemail' => '1', 'gotoid' => $tsvshop['backid'])), $tpl); // Плагин TSVshopOnUserFormComplete $evt = $modx->invokeEvent("TSVshopOnUserFormComplete", array("tpl" => $tpl)); if (is_array($evt) && !empty($evt[0])) { $tpl = $evt[0]; } } } else { $tpl = str_replace("[+shop.basket.userform+]", "", $tpl); } //добавлено с v5.3 ---------------------------------------------------- $tpl = str_replace("[+shop.basket.topay+]", $_SESSION[$session]['result']['topay'], $tpl); //запоминаем основные переменные $userid = $modx->getLoginUserID(); if (!$userid) { $userid = "0"; } $_SESSION[$session]['result']['userid'] = $userid; // Определяем ИД пользователя //Генерируем код доступа к заказу $tekens = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); for ($c = 0; $c < 8; $c++) { srand((double) microtime() * 100000000000000); $pass = $tekens[rand(0, 62)]; $accesskey = $accesskey . $pass; } $_SESSION[$session]['result']['code'] = $accesskey; } $evt = $modx->invokeEvent("TSVshopOnTplCartRender", array("tpl" => $tpl)); if (is_array($evt) && !empty($evt[0])) { $tpl = $evt[0]; } // Чистим чанк от всех меток $tpl = call_user_func_array(tsv_ClearTplfromLabels, array($tpl)); $tpl = preg_replace('/(\\[\\+.*?\\+\\])/', "", $tpl); $tpl = preg_replace('/(<!--.*?-->)/', "", $tpl); if (empty($tpl)) { return true; } else { return $divajax . $tpl; } unset($tpl); unset($piece); }