Пример #1
0
    function getContent($args)
    {
        global $structureMgr, $templatesMgr, $authenticationMgr;
        $userId = $authenticationMgr->getUserID();
        $userData = $authenticationMgr->getUserData($userId, '');
        $userName = $userData['FirstName'] . " " . $userData['LastName'];
        $this->setItemData('userData', $userData);
        $this->setItemData('userName', $userName);
        $blocks = $templatesMgr->getValidTags($templatesMgr->getTemplate(-1, GetCfg("TemplatesPath") . "/Cart/cart.xml"), array("container", "goods", "cart", "emptycart", "order", "quickorder", "login", "comment"));
        $sessionID = $authenticationMgr->getSessionID();
        $tpl = $blocks["container"];
        $goodsline = $blocks["goods"];
        $qr = mysql_query("SELECT p.sID, p.accID, p.ptID, ShortTitle, salePrice, accCount, ptPercent, p.accPlantID, logotype, p.smallPicture, s.MetaDesc, s.pms_sID, pc.PicturePath FROM pm_as_parts p \n                               LEFT JOIN pm_structure s ON (p.sID = s.sID) \n\t\t\t\t\t\t\t   LEFT JOIN pm_as_producer ap ON (ap.accPlantID = p.accPlantID)\n                               LEFT JOIN pm_as_cart c ON (c.accID = p.accID)\n                               LEFT JOIN pm_as_pricetypes pt ON (pt.ptID = p.ptID)\n                               LEFT JOIN pm_as_categories pc ON (s.pms_sID = pc.sID)\n                               WHERE c.sessionID='{$sessionID}'");
        if (!$qr) {
            trigger_error("Error getting cart items - \n" . mysql_error(), PM_FATAL);
        }
        $goodsCount = mysql_num_rows($qr);
        $goods = "";
        $cardSum = 0;
        $curSum = 0;
        $sum = 0;
        $total = 0;
        if (mysql_num_rows($qr) > 0) {
            $cat = new Catalogue();
            //goods list from $qr
            $goodsArray = array();
            while (false !== ($r = mysql_fetch_assoc($qr))) {
                /*
                	if ($catItem["ptPercent"] == 0)
                		$firstPrice = "<strong>" . round($catItem["salePrice"] - ($catItem["salePrice"] * 5 / 100)) . "</strong>";
                	else
                		$firstPrice = "<strong><font class=\"".$typeClass."\">" . 
                					  round($catItem["salePrice"] - ($catItem["salePrice"] * $catItem["ptPercent"] / 100)) . 
                					  "</font></strong>";
                */
                $gl = $goodsline;
                $URL = $structureMgr->getPathByPageID($r['sID'], false);
                $isCardInCart = Cart::isItemInCart(GetCfg('Club.GoodID'));
                $isClubMember = isset($userData['cardID']) && $userData['cardID'] != '0' || $isCardInCart;
                switch ($r['ptID']) {
                    case 1:
                        if ($userData['cardID'] || $isCardInCart) {
                            $curPrice = round($r["salePrice"] - $r["salePrice"] * 5 / 100);
                        } else {
                            $curPrice = $r['salePrice'];
                        }
                        $cardPrice = round($r["salePrice"] - $r["salePrice"] * 5 / 100);
                        break;
                    case 2:
                        if ($userData['cardID'] || $isCardInCart) {
                            $curPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        } else {
                            $curPrice = $r['salePrice'];
                        }
                        $cardPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        break;
                    case 3:
                        if ($userData['cardID'] || $isCardInCart) {
                            $curPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        } else {
                            $curPrice = $r['salePrice'];
                        }
                        $cardPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        break;
                    case 4:
                        if ($userData['cardID'] || $isCardInCart) {
                            $curPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        } else {
                            $curPrice = $r['salePrice'];
                        }
                        $cardPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        break;
                    case 5:
                        $curPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        $cardPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        break;
                    case 6:
                        $curPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        $cardPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        break;
                    case 7:
                        $curPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        $cardPrice = round($r["salePrice"] - $r["salePrice"] * $r["ptPercent"] / 100);
                        break;
                    default:
                        $curPrice = $r['salePrice'];
                        $cardPrice = $r['salePrice'];
                        break;
                }
                $curPrice *= $r["accCount"];
                $cardPrice *= $r["accCount"];
                $price = $r['salePrice'] * $r["accCount"];
                //must calc as needed
                $priceCells = '<td class="gray"><p> <a href="%good_link%" class="bluem" target="_blank">%good_name%</a></p></td>
                            <td><strong>%card_price%</strong></td>
                            <td>%cur_price%</td>';
                if ($isClubMember) {
                    $priceCells = '<td>%cur_price%</td>';
                }
                $gl = str_replace("%good_name%", $r['ShortTitle'], $gl);
                $gl = str_replace("%good_link%", $URL, $gl);
                $gl = str_replace("%card_price%", $cardPrice . " * " . $r["accCount"], $gl);
                $gl = str_replace("%cur_price%", $curPrice . " * " . $r["accCount"], $gl);
                $gl = str_replace("%price%", $price . " * " . $r["accCount"], $gl);
                $gl = str_replace("%good_count%", $r['accCount'], $gl);
                $gl = str_replace("%goodID%", $r['accID'], $gl);
                $cardSum += $cardPrice;
                $curSum += $curPrice;
                $sum += $price;
                $total += $r['accCount'];
                //echo "$curSum in Cart<br>";
                if (file_exists(GetCfg("ROOT") . $r["PicturePath"] . "/" . $r["sID"] . ".gif")) {
                    $r["smallPicture"] = $r["PicturePath"] . "/" . $r["sID"] . ".gif";
                } else {
                    if ($r["logotype"] == NULL) {
                        $r["smallPicture"] = "/products/empty.gif";
                    } else {
                        $r["smallPicture"] = $r["logotype"];
                    }
                }
                $good = new Good(array('goodID' => $r['sID'], 'good_name' => $r['ShortTitle'], 'PicturePath' => $r['PicturePath'], 'good_link' => $URL, 'card_price' => $cardPrice, 'smallPicture' => $r["smallPicture"], 'cur_price' => $curPrice, 'price' => $price, 'good_count' => $r['accCount']));
                foreach ($r as $var => $val) {
                    $good->setItemData($var, $val);
                }
                $good->setItemData('priceClass', $this->getPriceClass($r['ptID']));
                $good->setItemData('ptID', $r['ptID']);
                $good->setItemData('ptPercent', $r['ptPercent']);
                $good->setItemData('props', $props = $cat->getCatItemProperties($r['sID'], "CatItem", $structureMgr->getParentPageID($r['sID'])));
                $this->goods[$r['sID']] = $good;
                $imgRes = mysql_query("SELECT accPlantName, logotype FROM pm_as_producer WHERE accPlantID = '{$r["accPlantID"]}'");
                if (mysql_num_rows($imgRes) > 0) {
                    $imgRow = mysql_fetch_assoc($imgRes);
                    $this->goods[$r['sID']]->setItemData('accPlantName', $imgRow['accPlantName']);
                    $this->goods[$r['sID']]->setItemData('logotype', $imgRow['logotype']);
                }
                $goods .= $gl;
            }
            $tcart = $blocks["cart"];
        } else {
            $tcart = $blocks["emptycart"];
        }
        if ($total > 0) {
            $order = $blocks["order"];
            $qorder = $blocks["quickorder"];
            if ($authenticationMgr->getUserID() == 1) {
                $blocks["login"] = str_replace("%currentpath%", getenv("REQUEST_URI"), $blocks["login"]);
                $order = str_replace("%right%", $blocks["login"], $order);
                $order = str_replace("%left%", $qorder, $order);
            } else {
                $order = str_replace("%right%", $blocks["comment"], $order);
                $order = str_replace("%left%", $qorder, $order);
                //echo $order;
            }
        } else {
            $order = "";
        }
        $ret = '';
        $isCardInCart = Cart::isItemInCart(GetCfg('Club.GoodID'));
        $isClubMember = isset($userData['cardID']) && $userData['cardID'] != '0' || $isCardInCart;
        $this->setItemData('isCardInCart', $isCardInCart);
        $this->setItemData('isClubMember', $isClubMember);
        $this->setItemData('userID', $userId);
        $this->userData = $userData;
        $carName = 'марка автомобиля не определена';
        if ($userId > 1 && $isClubMember && $userData['carID'] != 0) {
            $carRow = mysql_fetch_assoc(mysql_query("SELECT * FROM pm_as_cars WHERE carID='{$userData['carID']}'"));
            $carName = "ВАЗ " . $carRow['carModel'] . (isset($carRow['carName']) && $carRow['carName'] != '' ? "({$carRow['carName']})" : '');
        }
        $this->setItemData('carName', $carName);
        if ($userId == 1) {
            $ret .= '<p><strong>Внимание!:</strong></p>
						<p>Для вашего удобства мы предлагаем вам:</p>
						<p><a href="/registration" class="levm"><img src="/images/arr_gray2.gif" width="7" height="9" border="0" align="absmiddle"/>Зарегестрироваться</a><br/>
						<a href="/main/club" class="levm"><img src="/images/arr_gray2.gif" width="7" height="9" border="0" align="absmiddle"/>Стать членом клуба</a></p>';
        } elseif ($userId > 1 && !$isClubMember) {
            $ret .= '<p><strong>Внимание:</strong></p>
						<p>Для вашего удобства мы предлагаем вам:</p>
						<a href="/main/club" class="levm"><img src="/images/arr_gray2.gif" width="7" height="9" border="0" align="absmiddle"/>Стать членом клуба</a></p>';
        } elseif ($userId > 1 && $isClubMember) {
            $carName = 'марка автомобиля не определена';
            if ($userData['carID'] != 0) {
                $carRow = mysql_fetch_assoc(mysql_query("SELECT * FROM pm_as_cars WHERE carID='{$userData['carID']}'"));
                $carName = "ВАЗ " . $carRow['carModel'] . (isset($carRow['carName']) && $carRow['carName'] != '' ? "({$carRow['carName']})" : '');
            }
            $ret .= '<p><strong>Здравствуйте!</strong></p>
						<p>' . $userName . '</p>
						<p>№ Вашей карты: ' . ($userData['cardID'] == '0' ? 'Будет присвоен после оплаты.' : $userData['cardID']) . '</p>
						<p>' . $carName . '</p>
						<p>
							<a href="#" class="levm"><img src="/images/arr_gray2.gif" width="7" height="9" border="0" align="absmiddle"/>Изменить анкету </a> 
						<a href="#" class="levm"><img src="/images/arr_gray2.gif" width="7" height="9" border="0" align="absmiddle"/>Выход (log out)</a></p>
						';
        }
        $club = $ret;
        $this->setItemData('cart', $tcart);
        $this->setItemData('cardsum', $cardSum);
        $this->setItemData('cursum', $curSum);
        $this->setItemData('sum', $sum);
        $this->setItemData('total', $total);
        $this->setItemData('goods', $goods);
        $this->setItemData('order', $order);
        $this->setItemData('club', $club);
        $dost = new Template('blockdost', $this);
        $this->setItemData('blockdost', $dost->getContent());
        if ($userId == 1) {
            $header = new Template('header', 'Быстрый заказ');
            $of = new Template('orderQuick');
            $orderForm = $header->getContent() . $of->getContent();
        } else {
            $header = new Template('header', 'Контактная информация');
            $of = new Template('orderUser', $this->getItemData('userData'));
            $orderForm = $header->getContent() . $of->getContent();
        }
        $this->setItemData('orderForm', $orderForm);
        $cartTpl = new Template('cart', $this);
        $tpl = $cartTpl->getContent();
        $msg = _get("msg");
        if ($msg == 1) {
            $msg = '<div class="podbor">Заполните пожалуйства поле &quot;Ваше имя&quot;</div>';
        } elseif ($msg == 2) {
            $msg = '<div class="podbor">Заполните пожалуйства поле &quot;Ваше имя&quot;</div>';
        }
        return $msg . $tpl;
    }