Add to the basket without reloading the page



  • Function code:

    function TDMPerocessAddToCart($arALLPRICES, $arPARTS) {
        if (isset($_POST["PHID"]) && strlen($_POST["PHID"]) == 32) {
            foreach ($arALLPRICES as $PKEY => $arPrcs) {
                foreach ($arPrcs as $arPrice) {
                    if (!($arPrice["PHID"] == $_POST["PHID"])) {
                        continue;
                    }
                    global $TDMCore;
                    $arPart = $arPARTS[$arPrice["BKEY"] . $arPrice["AKEY"]];
                    unset($arPrice["INFO"]);
                    unset($arPrice["EDIT_LINK"]);
                    if ($arPrice["ALT_NAME"] == "") {
                        $arPrice["NAME"] = $arPart["NAME"];
                    }
                    else {
                        $arPrice["NAME"] = $arPrice["ALT_NAME"];
                    }
                    unset($arPrice["ALT_NAME"]);
                    $arPrice["IMG_SRC"] = $arPart["IMG_SRC"];
                    $arPrice["ADD_URL"] = $_SERVER["REQUEST_URI"];
                    $arPrice["DETAIL_URL"] = $arPrice["ADD_URL"];
                    $arPrice["DATE_FORMATED"] = date("j.n.y", $arPrice["DATE"]);
                    $arPrice["CPID"] = substr(filter_var($arPrice["PHID"], FILTER_SANITIZE_NUMBER_INT), 0, 9);
                    $arPrice["TYPE_NAME"] = $TDMCore->arPriceType[$arPrice["TYPE"]];
                    if ($arPrice["STOCK"] != "") {
                        $arPrice["SUPPLIER_STOCK"] = $arPrice["SUPPLIER"] . " (" . $arPrice["STOCK"] . ")";
                    }
                    else {
                        $arPrice["SUPPLIER_STOCK"] = $arPrice["SUPPLIER"];
                    }
                    foreach ($arPrice["OPTIONS"] as $OpName => $OpValue) {
                        if ($OpName != "VIEW" && strpos($OpName, "_") <= 0) {
                            if ($OpValue == "" || $OpValue == "0") {
                                unset($arPrice["OPTIONS"][$OpName]);
                                continue;
                            }
                            $arPrice["OPTIONS_NAMES"][$OpName] = Lng("PRICE_OPTION_" . $OpName, 1, 0);
                            continue;
                        }
                        unset($arPrice["OPTIONS"][$OpName]);
                    }
                    define("TDM_ADD_TO_CART", true);
                    global $arCartPrice;
                    $arCartPrice = $arPrice;
                    return $arPrice["PHID"];
                }
            }
        }
        return false;
    }
    

    How do you get through ajax?

    Clinic:

    <?foreach($arResult['PRICES'] as $arPrice) foreach($arPrice as $key=>$value) {?>
    
        &lt;?if(in_array($_REQUEST['article'],$value)) echo '&lt;b&gt;В наличии:&lt;/b&gt; '.$value['AVAILABLE']."&lt;/br&gt;"?&gt;
        &lt;?if(in_array($_REQUEST['article'],$value)) echo '&lt;b&gt;Доставка:&lt;/b&gt; '.$value['DAY']." дней&lt;/br&gt;"?&gt;
    
        &lt;?if(in_array($_REQUEST['article'],$value)) if($arResult['ADDED_PHID']!=$arPrice['PHID']) {?&gt;
            &lt;a href="/index.php?route=checkout/simplecheckout" class="btn btn-success" title="Оформить заказ"&gt;&lt;?=$value['PRICE_FORMATED']?&gt; &lt;?=TDM_CUR_LABEL?&gt; - Оформить&lt;/a&gt;
          &lt;?}else{?&gt;
            &lt;a href="javascript:void(0)" OnClick="TDMAddToCart('&lt;?=$value['PHID']?&gt;')" title="&lt;?=Lng('Add_to_cart',1,0)?&gt;"&gt;&lt;?=$value['PRICE_FORMATED']?&gt; &lt;?=TDM_CUR_LABEL?&gt; - Купить&lt;/a&gt;
        &lt;?}?&gt;
    

    <?}?>

    When compressed, the goods are stored in the basket and the page is overloaded.

    I haven't tried anything since I can't figure out where to start.



  • To do something without reloading, of course AJAX. And there's no way you're gonna work out some sort of code on the server.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2