Documentation

GetByID

array
CSaleBasket::GetByID(
  int ID
);

The method GetByID returns an array of parameters of the shopping basket record identified by the ID.

Parameters

ParameterDescription
ID The record ID.

Return Values

The method returns an associated array with the following keys.

Key Description
ID The record ID.
PRODUCT_ID The product ID unique within the module.
PRODUCT_PRICE_ID The product ID (auxiliary).
PRICE Price of the product, per unit.
CURRENCY Currency of the product price.
WEIGHT Weight of the product unit.
QUANTITY Number of products.
LID The site from which the purchase originates.
DELAY Indicates the product item is saved for later purchase (Y/N).
CAN_BUY Indicates the product can be purchased (Y/N).
NAME The product name.
CALLBACK_FUNC Name of the callback function used to maintain the basket actuals.
MODULE Module adding the product to the basket.
NOTES Other special notes.
ORDER_CALLBACK_FUNC Name of the ordering process callback function.
DETAIL_PAGE_URL URL of the page with the product details.
FUSER_ID The internal ID of the basket owner (not the same as the user ID).
ORDER_ID The ID of the sale order containing this record (product). If a product is in the basket but is not ordered yet, this field is NULL.
DATE_INSERT The date the product was added.
DATE_UPDATE The date the record was modified.
DISCOUNT_PRICE Discount for the product. Valid only upon ordering.

Please note that this method returns data which is actual by the time of the last call of the CALLBACK_FUNC callback function on this record, or by the time the record was added if the callback function was not called or is not specified.

Example


<?
// Display the actual basket of the current user
// (implemented by the API function GetBasketList())

// initialise the basket owner internal ID
CSaleBasket::Init(false);

// Result array
$arRes = array();

// Select all active but not ordered records 
// of the current owner for the current site
$db_res = CSaleBasket::GetList(($by="NAME"), ($order="ASC"), 
                               array("FUSER_ID"=>$_SESSION["SALE_USER_ID"], 
                                     "LID"=>SITE_ID, "ORDER_ID"=>"NULL"));

while ($ar_res = $db_res->GetNext())
{
    // If the callback function is specified...
    if (strlen($ar_res["CALLBACK_FUNC"])>0)
    {
        // Update the basket parameters by calling the callback function
        CSaleBasket::UpdatePrice($ar_res["ID"], 
                                 $ar_res["CALLBACK_FUNC"], 
                                 $ar_res["MODULE"], 
                                 $ar_res["PRODUCT_ID"], 
                                 $ar_res["QUANTITY"]);
        // Query an array of newly actual parameters
        $ar_res = CSaleBasket::GetByID($ar_res["ID"]);
    }
    $arRes[] = $ar_res;
}

// Display the actual basket information
echo "<pre>";
print_r($arRes);
echo "</pre>";
?>
© «Bitrix24», 2001-2024