本文整理汇总了PHP中CSaleBasket::Add方法的典型用法代码示例。如果您正苦于以下问题:PHP CSaleBasket::Add方法的具体用法?PHP CSaleBasket::Add怎么用?PHP CSaleBasket::Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSaleBasket
的用法示例。
在下文中一共展示了CSaleBasket::Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addProductToCart
public function addProductToCart(Product $product, $quantity)
{
Loader::includeModule('sale');
$price = reset($product['PRICES']);
$properties = array();
foreach ($product->getShopParameters() as $name => $value) {
$properties[] = array('NAME' => $name, 'VALUE' => $value);
}
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
\CSaleBasket::Add(array('PRODUCT_ID' => $product['ID'], 'PRODUCT_PRICE_ID' => $price['ID'], 'PRICE' => $price['PRICE'], 'CURRENCY' => $price['CURRENCY'], 'QUANTITY' => $quantity, 'LID' => SITE_ID, 'NAME' => $product['NAME'], 'NOTES' => $product['DETAIL_TEXT'], 'PROPS' => $properties));
}
示例2: elseif
if (strlen($_REQUEST[$arParams["VAR"]]) > 0) {
$productID = $_REQUEST[$arParams["VAR"]];
if (!empty($arResult["PAY_ACCOUNT_AMOUNT"][$productID])) {
$price = $arResult["PAY_ACCOUNT_AMOUNT"][$productID]["AMOUNT"];
$currency = $arResult["PAY_ACCOUNT_AMOUNT"][$productID]["CURRENCY"];
$tmpPrice = $price;
$tmpCurrency = $currency;
if ($currency != $arParams["SELL_CURRENCY"] && strlen($arParams["SELL_CURRENCY"]) > 0) {
$tmpPrice = CCurrencyRates::ConvertCurrency($price, $currency, $arParams["SELL_CURRENCY"]);
$tmpCurrency = $arParams["SELL_CURRENCY"];
} elseif ($currency != $baseCurrency) {
$tmpPrice = CCurrencyRates::ConvertCurrency($price, $currency, $baseCurrency);
$tmpCurrency = $baseCurrency;
}
$arFields = array("PRODUCT_ID" => $productID, "PRICE" => $tmpPrice, "CURRENCY" => $tmpCurrency, "QUANTITY" => 1, "LID" => SITE_ID, "DELAY" => "N", "CAN_BUY" => "Y", "NAME" => str_replace("#SUM#", SaleFormatCurrency($price, $currency), GetMessage("SAP_BASKET_NAME")), "MODULE" => "sale", "PAY_CALLBACK_FUNC" => $arParams["CALLBACK_NAME"]);
$basketID = CSaleBasket::Add($arFields);
if ($basketID) {
if (CModule::IncludeModule("statistic")) {
CStatistic::Set_Event("sale2basket", "sale", $productID);
}
if ($arParams["REDIRECT_TO_CURRENT_PAGE"] == "Y") {
LocalRedirect($arResult["CURRENT_PAGE"]);
} elseif ($arParams["REDIRECT_TO_CURRENT_PAGE"] != "Y") {
LocalRedirect($arParams["PATH_TO_BASKET"]);
}
} else {
$arResult["errorMessage"] = GetMessage("SAP_ERROR_ADD_BASKET") . "<br>";
if ($ex = $GLOBALS["APPLICATION"]->GetException()) {
$arResult["errorMessage"] .= $ex->GetString();
}
}
示例3: SubscribeProduct
//.........这里部分代码省略.........
if ($intProductID <= 0) {
$APPLICATION->ThrowException(Loc::getMessage('CATALOG_ERR_EMPTY_PRODUCT_ID'), "EMPTY_PRODUCT_ID");
return false;
}
if (!Loader::includeModule("sale")) {
$APPLICATION->ThrowException(Loc::getMessage('CATALOG_ERR_NO_SALE_MODULE'), "NO_SALE_MODULE");
return false;
}
if (Loader::includeModule("statistic") && isset($_SESSION['SESS_SEARCHER_ID']) && (int) $_SESSION["SESS_SEARCHER_ID"] > 0) {
$APPLICATION->ThrowException(Loc::getMessage('CATALOG_ERR_SESS_SEARCHER'), "SESS_SEARCHER");
return false;
}
$rsProducts = CCatalogProduct::GetList(array(), array('ID' => $intProductID), false, false, array('ID', 'WEIGHT', 'WIDTH', 'HEIGHT', 'LENGTH', 'TYPE', 'MEASURE', 'SUBSCRIBE'));
if (!($arCatalogProduct = $rsProducts->Fetch())) {
$APPLICATION->ThrowException(Loc::getMessage('CATALOG_ERR_NO_PRODUCT'), "NO_PRODUCT");
return false;
}
if ($arCatalogProduct['SUBSCRIBE'] == 'N') {
$APPLICATION->ThrowException(Loc::getMessage('CATALOG_ERR_NO_SUBSCRIBE'), 'SUBSCRIBE');
return false;
}
$arCatalogProduct['MEASURE'] = (int) $arCatalogProduct['MEASURE'];
$arCatalogProduct['MEASURE_NAME'] = '';
$arCatalogProduct['MEASURE_CODE'] = 0;
if ($arCatalogProduct['MEASURE'] <= 0) {
$arMeasure = CCatalogMeasure::getDefaultMeasure(true, true);
$arCatalogProduct['MEASURE_NAME'] = $arMeasure['~SYMBOL_RUS'];
$arCatalogProduct['MEASURE_CODE'] = $arMeasure['CODE'];
} else {
$rsMeasures = CCatalogMeasure::getList(array(), array('ID' => $arCatalogProduct['MEASURE']), false, false, array('ID', 'SYMBOL_RUS', 'CODE'));
if ($arMeasure = $rsMeasures->GetNext()) {
$arCatalogProduct['MEASURE_NAME'] = $arMeasure['~SYMBOL_RUS'];
$arCatalogProduct['MEASURE_CODE'] = $arMeasure['CODE'];
}
}
$rsItems = CIBlockElement::GetList(array(), array("ID" => $intProductID, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "CHECK_PERMISSIONS" => "Y", "MIN_PERMISSION" => "R"), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'XML_ID', 'DETAIL_PAGE_URL'));
if (!($arProduct = $rsItems->GetNext())) {
return false;
}
$arParentSku = CCatalogSku::GetProductInfo($intProductID, $arProduct['IBLOCK_ID']);
if (!empty($arParentSku)) {
if (strpos($arProduct["~XML_ID"], '#') === false) {
$parentIterator = Iblock\ElementTable::getList(array('select' => array('ID', 'XML_ID'), 'filter' => array('ID' => $arParentSku['ID'])));
if ($parent = $parentIterator->fetch()) {
$arProduct["~XML_ID"] = $parent['XML_ID'] . '#' . $arProduct["~XML_ID"];
}
unset($parent, $parentIterator);
}
}
$arPrice = array('PRICE' => 0.0, 'CURRENCY' => CSaleLang::GetLangCurrency(SITE_ID), 'VAT_RATE' => 0, 'PRODUCT_PRICE_ID' => 0, 'CATALOG_GROUP_NAME' => '');
$arBuyerGroups = $USER->GetUserGroupArray();
$arSubscrPrice = CCatalogProduct::GetOptimalPrice($intProductID, 1, $arBuyerGroups, "N", array(), SITE_ID, array());
if (!empty($arSubscrPrice) && is_array($arSubscrPrice)) {
$arPrice['PRICE'] = $arSubscrPrice['DISCOUNT_PRICE'];
$arPrice['CURRENCY'] = CCurrency::GetBaseCurrency();
$arPrice['VAT_RATE'] = $arSubscrPrice['PRICE']['VAT_RATE'];
$arPrice['PRODUCT_PRICE_ID'] = $arSubscrPrice["PRICE"]["ID"];
$arPrice['CATALOG_GROUP_NAME'] = $arSubscrPrice["PRICE"]["CATALOG_GROUP_NAME"];
}
$arProps = array();
$strIBlockXmlID = (string) CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], 'XML_ID');
if ($strIBlockXmlID !== '') {
$arProps[] = array("NAME" => "Catalog XML_ID", "CODE" => "CATALOG.XML_ID", "VALUE" => $strIBlockXmlID);
}
if (!empty($arProductParams) && is_array($arProductParams)) {
foreach ($arProductParams as &$arOneProductParams) {
$arProps[] = array("NAME" => $arOneProductParams["NAME"], "CODE" => $arOneProductParams["CODE"], "VALUE" => $arOneProductParams["VALUE"], "SORT" => $arOneProductParams["SORT"]);
}
unset($arOneProductParams);
}
$arProps[] = array("NAME" => "Product XML_ID", "CODE" => "PRODUCT.XML_ID", "VALUE" => $arProduct["XML_ID"]);
$arFields = array("PRODUCT_ID" => $intProductID, "PRODUCT_PRICE_ID" => $arPrice['PRODUCT_PRICE_ID'], "PRICE" => $arPrice['PRICE'], "CURRENCY" => $arPrice['CURRENCY'], "WEIGHT" => $arCatalogProduct["WEIGHT"], "DIMENSIONS" => serialize(array("WIDTH" => $arCatalogProduct["WIDTH"], "HEIGHT" => $arCatalogProduct["HEIGHT"], "LENGTH" => $arCatalogProduct["LENGTH"])), "QUANTITY" => 1, "LID" => SITE_ID, "DELAY" => "N", "CAN_BUY" => "N", "SUBSCRIBE" => "Y", "NAME" => $arProduct["~NAME"], "MODULE" => "catalog", "PRODUCT_PROVIDER_CLASS" => "CCatalogProductProvider", "NOTES" => $arPrice["CATALOG_GROUP_NAME"], "DETAIL_PAGE_URL" => $arProduct["~DETAIL_PAGE_URL"], "CATALOG_XML_ID" => $strIBlockXmlID, "PRODUCT_XML_ID" => $arProduct["~XML_ID"], "PROPS" => $arProps, "TYPE" => $arCatalogProduct["TYPE"] == CCatalogProduct::TYPE_SET ? CCatalogProductSet::TYPE_SET : NULL, "MEASURE_NAME" => $arCatalogProduct['MEASURE_NAME'], "MEASURE_CODE" => $arCatalogProduct['MEASURE_CODE'], 'IGNORE_CALLBACK_FUNC' => 'Y');
if (!empty($arRewriteFields) && is_array($arRewriteFields)) {
if (array_key_exists('SUBSCRIBE', $arRewriteFields)) {
unset($arRewriteFields['SUBSCRIBE']);
}
if (array_key_exists('CAN_BUY', $arRewriteFields)) {
unset($arRewriteFields['CAN_BUY']);
}
if (array_key_exists('DELAY', $arRewriteFields)) {
unset($arRewriteFields['DELAY']);
}
if (!empty($arRewriteFields)) {
$arFields = array_merge($arFields, $arRewriteFields);
}
}
$mxBasketID = CSaleBasket::Add($arFields);
if ($mxBasketID) {
if (!isset($_SESSION['NOTIFY_PRODUCT'])) {
$_SESSION['NOTIFY_PRODUCT'] = array($intUserID = array());
} elseif (!isset($_SESSION['NOTIFY_PRODUCT'][$intUserID])) {
$_SESSION['NOTIFY_PRODUCT'][$intUserID] = array();
}
$_SESSION["NOTIFY_PRODUCT"][$intUserID][$intProductID] = $intProductID;
if (Loader::includeModule("statistic")) {
CStatistic::Set_Event("sale2basket", "subscribe", $intProductID);
}
}
return $mxBasketID;
}
示例4: trim
global $APPLICATION;
$APPLICATION->RestartBuffer();
$brandName = trim($_GET['brandName']);
$categId = (int) trim($_GET['categId']);
$brandId = (int) trim($_GET['brandId']);
if ($brandId !== 1) {
global $arrFilterSection2;
$arrFilterSection2 = sest::setCatFilter('BRAND', $brandName);
}
$APPLICATION->IncludeComponent("sest:catalog.section", "", array("IBLOCK_TYPE_ID" => "catalog", "IBLOCK_ID" => IBLOCK_ID_PRODUCTS, "BASKET_URL" => "/personal/cart/", "COMPONENT_TEMPLATE" => "", "IBLOCK_TYPE" => "catalog", "SECTION_ID" => $categId !== 1 ? $categId : '', "SECTION_CODE" => "", "SECTION_USER_FIELDS" => array(0 => "", 1 => ""), "ELEMENT_SORT_FIELD" => "sort", "ELEMENT_SORT_ORDER" => "desc", "ELEMENT_SORT_FIELD2" => "id", "ELEMENT_SORT_ORDER2" => "desc", "FILTER_NAME" => "arrFilterSection2", "INCLUDE_SUBSECTIONS" => "Y", "SHOW_ALL_WO_SECTION" => "Y", "HIDE_NOT_AVAILABLE" => "N", "PAGE_ELEMENT_COUNT" => "16", "LINE_ELEMENT_COUNT" => "4", "PROPERTY_CODE" => array(0 => "", 1 => ""), "OFFERS_FIELD_CODE" => array(0 => "", 1 => ""), "OFFERS_PROPERTY_CODE" => array(0 => "COLOR_REF", 1 => "SIZES_SHOES", 2 => "SIZES_CLOTHES", 3 => ""), "OFFERS_SORT_FIELD" => "sort", "OFFERS_SORT_ORDER" => "desc", "OFFERS_SORT_FIELD2" => "id", "OFFERS_SORT_ORDER2" => "desc", "OFFERS_LIMIT" => "5", "TEMPLATE_THEME" => "site", "PRODUCT_DISPLAY_MODE" => "Y", "ADD_PICT_PROP" => "MORE_PHOTO", "LABEL_PROP" => "-", "OFFER_ADD_PICT_PROP" => "-", "OFFER_TREE_PROPS" => array(), "PRODUCT_SUBSCRIPTION" => "N", "SHOW_DISCOUNT_PERCENT" => "N", "SHOW_OLD_PRICE" => "Y", "SHOW_CLOSE_POPUP" => "N", "MESS_BTN_BUY" => "Купить", "MESS_BTN_ADD_TO_BASKET" => "В корзину", "MESS_BTN_SUBSCRIBE" => "Подписаться", "MESS_BTN_DETAIL" => "Подробнее", "MESS_NOT_AVAILABLE" => "Нет в наличии", "SECTION_URL" => "", "DETAIL_URL" => "", "SECTION_ID_VARIABLE" => "SECTION_ID", "SEF_MODE" => "N", "AJAX_MODE" => "N", "AJAX_OPTION_JUMP" => "N", "AJAX_OPTION_STYLE" => "Y", "AJAX_OPTION_HISTORY" => "N", "AJAX_OPTION_ADDITIONAL" => "", "CACHE_TYPE" => "A", "CACHE_TIME" => "36000000", "CACHE_GROUPS" => "Y", "SET_TITLE" => "Y", "SET_BROWSER_TITLE" => "Y", "BROWSER_TITLE" => "-", "SET_META_KEYWORDS" => "Y", "META_KEYWORDS" => "-", "SET_META_DESCRIPTION" => "Y", "META_DESCRIPTION" => "-", "SET_LAST_MODIFIED" => "N", "USE_MAIN_ELEMENT_SECTION" => "N", "ADD_SECTIONS_CHAIN" => "N", "CACHE_FILTER" => "N", "ACTION_VARIABLE" => "action", "PRODUCT_ID_VARIABLE" => "id", "PRICE_CODE" => array(0 => "BASE"), "USE_PRICE_COUNT" => "N", "SHOW_PRICE_COUNT" => "1", "PRICE_VAT_INCLUDE" => "Y", "CONVERT_CURRENCY" => "Y", "USE_PRODUCT_QUANTITY" => "N", "PRODUCT_QUANTITY_VARIABLE" => "", "ADD_PROPERTIES_TO_BASKET" => "Y", "PRODUCT_PROPS_VARIABLE" => "prop", "PARTIAL_PRODUCT_PROPERTIES" => "N", "PRODUCT_PROPERTIES" => array(), "OFFERS_CART_PROPERTIES" => array(), "ADD_TO_BASKET_ACTION" => "ADD", "PAGER_TEMPLATE" => "round", "DISPLAY_TOP_PAGER" => "N", "DISPLAY_BOTTOM_PAGER" => "N", "PAGER_TITLE" => "Товары", "PAGER_SHOW_ALWAYS" => "N", "PAGER_DESC_NUMBERING" => "N", "PAGER_DESC_NUMBERING_CACHE_TIME" => "36000", "PAGER_SHOW_ALL" => "N", "PAGER_BASE_LINK_ENABLE" => "N", "SET_STATUS_404" => "N", "SHOW_404" => "N", "MESSAGE_404" => "", "BACKGROUND_IMAGE" => "-", "CURRENCY_ID" => "USD", "DISABLE_INIT_JS_IN_COMPONENT" => "N"), false);
}
}
?>
<?php
//без провайдера
$arFields = array("PRODUCT_ID" => $pid, "PRICE" => $ar_res['PRICES'][$arrPriceCodes[0]]['PRICE'], "CURRENCY" => "UAH", "QUANTITY" => $quantity, "LID" => LANG, "DELAY" => "N", "CAN_BUY" => "Y", "NAME" => $ar_res['NAME'], "PRODUCT_XML_ID" => $ar_res['XML_ID'], "CATALOG_XML_ID" => $iblockId['XML_ID'], "CALLBACK_FUNC" => "", "MODULE" => "catalog", "NOTES" => "", "DETAIL_PAGE_URL" => $ar_res['DETAIL_PAGE_URL'], "ORDER_ID" => $orderid);
$arProps = array();
$arProps[] = array('NAME' => 'Наличие', 'SORT' => 20, 'CODE' => 'STATUS_AVAIL', 'VALUE' => true);
$arProps[] = array('NAME' => 'Catalog XML_ID', 'SORT' => 30, 'CODE' => 'Catalog XML_ID', 'VALUE' => $iblockId['XML_ID']);
$arFields["PROPS"] = $arProps;
$result = CSaleBasket::Add($arFields);
?>
示例5: Add2BasketCustom
/**
* Добавление в корзину
* аналогично системной функции Add2Basket за исключением использования кастомизированных функций обратного вызова
* также в функции отключена статистика
*
* @param $PRICE_ID
* @param $QUANTITY
* @param $arRewriteFields
* @param $arProductParams
*/
function Add2BasketCustom($PRICE_ID, $QUANTITY = 1, $arRewriteFields=array(), $arProductParams = array())
{
$PRICE_ID = IntVal($PRICE_ID);
if ($PRICE_ID<=0) return false;
$QUANTITY = DoubleVal($QUANTITY);
if ($QUANTITY<=0) $QUANTITY = 1;
if (!CModule::IncludeModule("sale"))
return false;
$arPrice = CPrice::GetByID($PRICE_ID);
if ($arPrice===false) return false;
$arCatalogProduct = CCatalogProduct::GetByID($arPrice["PRODUCT_ID"]);
if ($arCatalogProduct["QUANTITY_TRACE"]=="Y" && DoubleVal($arCatalogProduct["QUANTITY"])<=0)
return false;
// $arProduct = GetIBlockElement($arPrice["PRODUCT_ID"]);
$dbIBlockElement = CIBlockElement::GetList(
array(),
array(
"ID" => $arPrice["PRODUCT_ID"],
"ACTIVE_DATE" => "Y",
"ACTIVE" => "Y",
"CHECK_PERMISSIONS" => "Y"
)
);
$arProduct = $dbIBlockElement->GetNext();
$arProps = array();
$dbIBlock = CIBlock::GetList(
array(),
array("ID" => $arProduct["IBLOCK_ID"])
);
if ($arIBlock = $dbIBlock->Fetch())
{
$arProps[] = array(
"NAME" => "Catalog XML_ID",
"CODE" => "CATALOG.XML_ID",
"VALUE" => $arIBlock["XML_ID"]
);
}
$arProps[] = array(
"NAME" => "Product XML_ID",
"CODE" => "PRODUCT.XML_ID",
"VALUE" => $arProduct["XML_ID"]
);
$arFields = array(
"PRODUCT_ID" => $arPrice["PRODUCT_ID"],
"PRODUCT_PRICE_ID" => $PRICE_ID,
"PRICE" => $arPrice["PRICE"],
"CURRENCY" => $arPrice["CURRENCY"],
"WEIGHT" => $arCatalogProduct["WEIGHT"],
"QUANTITY" => $QUANTITY,
"LID" => LANG,
"DELAY" => "N",
"CAN_BUY" => "Y",
"NAME" => $arProduct["~NAME"],
"CALLBACK_FUNC" => "CatalogBasketCustomCallback",
"MODULE" => "catalog",
"NOTES" => $arPrice["CATALOG_GROUP_NAME"],
"ORDER_CALLBACK_FUNC" => "CatalogBasketOrderCustomCallback",
"CANCEL_CALLBACK_FUNC" => "CatalogBasketCancelCallback",
"PAY_CALLBACK_FUNC" => "CatalogPayOrderCallback",
"DETAIL_PAGE_URL" => $arProduct["DETAIL_PAGE_URL"],
"CATALOG_XML_ID" => $arIBlock["XML_ID"],
"PRODUCT_XML_ID" => $arProduct["XML_ID"]
);
if ($arCatalogProduct["QUANTITY_TRACE"]=="Y")
{
if (DoubleVal($arCatalogProduct["QUANTITY"])-$QUANTITY<0)
$arFields["QUANTITY"] = DoubleVal($arCatalogProduct["QUANTITY"]);
}
if (is_array($arProductParams) && count($arProductParams) > 0)
{
for ($i = 0; $i < count($arProductParams); $i++)
{
$arProps[] = array(
"NAME" => $arProductParams[$i]["NAME"],
"CODE" => $arProductParams[$i]["CODE"],
"VALUE" => $arProductParams[$i]["VALUE"]
);
}
}
$arFields["PROPS"] = $arProps;
//.........这里部分代码省略.........
示例6: AuthtorizeAfterAds
/**
* функция после добавлением элемента в инфоблока
* @param $arFields поля элемента ифоблока
* для страницы Объявления
* eсли VIP объявление то добавляет корзину
* привязывает по ID созданное объявления к товару в корзине
* редирект на необходимы url
*/
function AuthtorizeAfterAds(&$arFields){
unset($_SESSION['user777999authorize']);
if($arFields['PROPERTY_VALUES']['114']){
foreach($arFields['PROPERTY_VALUES']['114'] as $key114 => $item114){
if($item114['VALUE']){
foreach($arFields['PROPERTY_VALUES']['113'] as $key113 => $item113){
if($item113['VALUE']){
$arFields['PROPERTY_VALUES']['113'][$key113]=ConvertDateTime($item114['VALUE'], "YYYY-MM-DD HH:MI:SS");
}else{
$arFields['PROPERTY_VALUES']['113'][n0]=ConvertDateTime($item114['VALUE'], "YYYY-MM-DD HH:MI:SS");
}
}
}
}
}
if(($arFields["IBLOCK_ID"] == 16)&&(!CUser::IsAuthorized())){
global $USER;
$rsUser = CUser::GetByID($_SESSION['NEW_USER_ID']);
$arUser = $rsUser->Fetch();
$_SESSION['$arUser']=$arUser;
$USER = new CUser;
$arAuthResult = $USER->Login($arUser['LOGIN'], $arUser['PASSWORD'], "Y","N");
}
//$_SESSION['user777authorize']=$arFields;
if(($arFields["IBLOCK_ID"] == 16)&&(CModule::IncludeModule("catalog"))&&(CModule::IncludeModule("sale"))){
$price_product=floatval($arFields["PROPERTY_VALUES"][86]);
$quantity_product=floatval($arFields["PROPERTY_VALUES"][87]);
if($price_product){
$PRODUCT_ID = $arFields['ID'];
$PRICE_TYPE_ID = 1;
$arFieldsprice = Array(
"PRODUCT_ID" => $PRODUCT_ID,
"CATALOG_GROUP_ID" => $PRICE_TYPE_ID,
"PRICE" =>$price_product,
"CURRENCY" => "RUB",
"QUANTITY_FROM" => 1,
);
$res = CPrice::GetList(
array(),
array(
"PRODUCT_ID" => $PRODUCT_ID,
"CATALOG_GROUP_ID" => $PRICE_TYPE_ID
)
);
if ($arr = $res->Fetch())
{
CPrice::Update($arr["ID"], $arFieldsprice);
}
else
{
CPrice::Add($arFieldsprice,true);
}
}
}
if (
(
(($arFields["IBLOCK_ID"] == 2)&& (is_numeric($arFields["PROPERTY_VALUES"][73])))
||
(($arFields["IBLOCK_ID"] == 15)&& (is_numeric($arFields["PROPERTY_VALUES"][76])))
||
(($arFields["IBLOCK_ID"] == 14)&& (is_numeric($arFields["PROPERTY_VALUES"][78])))
)
&&
CModule::IncludeModule("catalog")
&&
CModule::IncludeModule("sale")
&&
((strstr($_SERVER['REQUEST_URI'],'/personal/moy-magazin/'))||(strstr($_SERVER['REQUEST_URI'],'/obyavleniya/add-ads/')))
)
{
switch($arFields["IBLOCK_ID"]){
case 2:
$price_product=floatval($arFields["PROPERTY_VALUES"][73]);
$quantity_product=floatval($arFields["PROPERTY_VALUES"][75]);
break;
case 14:
$price_product=floatval($arFields["PROPERTY_VALUES"][78]);
$quantity_product=floatval($arFields["PROPERTY_VALUES"][79]);
//.........这里部分代码省略.........
示例7: __MakeOrder
function __MakeOrder($prdCnt=1, $arData = Array())
{
global $APPLICATION, $USER, $DB;
CModule::IncludeModule("iblock");
CModule::IncludeModule("sale");
CModule::IncludeModule("catalog");
$arPrd = Array();
$dbItem = CIBlockElement::GetList(Array("PROPERTY_MORE_PHOTO" => "DESC", "ID" => "ASC"), Array("IBLOCK_TYPE" => "offers", "IBLOCK_SITE_ID" => WIZARD_SITE_ID, "PROPERTY_NEWPRODUCT" => false), false, Array("nTopCount" => 10), Array("ID", "IBLOCK_ID", "XML_ID", "NAME", "DETAIL_PAGE_URL", "IBLOCK_XML_ID"));
while($arItem = $dbItem->GetNext())
$arPrd[] = $arItem;
if(!empty($arPrd))
{
for($i=0; $i<$prdCnt;$i++)
{
$prdID = $arPrd[mt_rand(0, 9)];
$arProduct = CCatalogProduct::GetByID($prdID["ID"]);
$CALLBACK_FUNC = "";
$arCallbackPrice = CSaleBasket::ReReadPrice($CALLBACK_FUNC, "catalog", $prdID["ID"], 1);
$arFields = array(
"PRODUCT_ID" => $prdID["ID"],
"PRODUCT_PRICE_ID" => $arCallbackPrice["PRODUCT_PRICE_ID"],
"PRICE" => $arCallbackPrice["PRICE"],
"CURRENCY" => $arCallbackPrice["CURRENCY"],
"WEIGHT" => $arProduct["WEIGHT"],
"QUANTITY" => 1,
"LID" => WIZARD_SITE_ID,
"DELAY" => "N",
"CAN_BUY" => "Y",
"NAME" => $prdID["NAME"],
"CALLBACK_FUNC" => $CALLBACK_FUNC,
"MODULE" => "catalog",
"PRODUCT_PROVIDER_CLASS" => "CCatalogProductProvider",
"ORDER_CALLBACK_FUNC" => "",
"CANCEL_CALLBACK_FUNC" => "",
"PAY_CALLBACK_FUNC" => "",
"DETAIL_PAGE_URL" => $prdID["DETAIL_PAGE_URL"],
"CATALOG_XML_ID" => $prdID["IBLOCK_XML_ID"],
"PRODUCT_XML_ID" => $prdID["XML_ID"],
"VAT_RATE" => $arCallbackPrice['VAT_RATE'],
);
$addres = CSaleBasket::Add($arFields);
}
$arOrder = Array(
"LID" => $arData["SITE_ID"],
"PERSON_TYPE_ID" => $arData["PERSON_TYPE_ID"],
"PAYED" => "N",
"CANCELED" => "N",
"STATUS_ID" => "N",
"PRICE" => 1,
"CURRENCY" => $arData["CURRENCY"],
"USER_ID" => $arData["USER_ID"],
"PAY_SYSTEM_ID" => $arData["PAY_SYSTEM_ID"],
//"PRICE_DELIVERY" => $arData["PRICE_DELIVERY"],
//"DELIVERY_ID" => $arData["DELIVERY_ID"],
);
$dbFUserListTmp = CSaleUser::GetList(array("USER_ID" => $arData["USER_ID"]));
if(empty($dbFUserListTmp))
{
$arFields = array(
"=DATE_INSERT" => $DB->GetNowFunction(),
"=DATE_UPDATE" => $DB->GetNowFunction(),
"USER_ID" => $arData["USER_ID"]
);
$ID = CSaleUser::_Add($arFields);
}
$orderID = CSaleOrder::Add($arOrder);
CSaleBasket::OrderBasket($orderID, CSaleBasket::GetBasketUserID(), WIZARD_SITE_ID);
$dbBasketItems = CSaleBasket::GetList(
array("NAME" => "ASC"),
array(
"FUSER_ID" => CSaleBasket::GetBasketUserID(),
"LID" => WIZARD_SITE_ID,
"ORDER_ID" => $orderID
),
false,
false,
array("ID", "CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "QUANTITY", "DELAY", "CAN_BUY", "PRICE", "WEIGHT", "NAME")
);
$ORDER_PRICE = 0;
while ($arBasketItems = $dbBasketItems->GetNext())
{
$ORDER_PRICE += roundEx($arBasketItems["PRICE"], SALE_VALUE_PRECISION) * DoubleVal($arBasketItems["QUANTITY"]);
}
$totalOrderPrice = $ORDER_PRICE + $arData["PRICE_DELIVERY"];
CSaleOrder::Update($orderID, Array("PRICE" => $totalOrderPrice));
foreach($arData["PROPS"] as $val)
{
$arFields = Array(
"ORDER_ID" => $orderID,
"ORDER_PROPS_ID" => $val["ID"],
"NAME" => $val["NAME"],
"CODE" => $val["CODE"],
"VALUE" => $val["VALUE"],
//.........这里部分代码省略.........
示例8: intval
//добавление товара в корзину
//$allproducts = explode("-", $_REQUEST["productid"]);
//foreach ($allproducts as $product) {
$product = intval($_REQUEST["productid"]);
//$product = intval($_POST["add2basket"]);
//проверим
$res = CIBlockElement::GetByID($product);
if ($ar_res = $res->GetNext()) {
$arProps = array();
$PRODUCT = $ar_res;
$ar_res = CPrice::GetBasePrice($PRODUCT[ID]);
$price = $ar_res["PRICE"];
if (intval($price) == 0) {
$price = 0;
$arFields = array("PRODUCT_ID" => $PRODUCT[ID], "QUANTITY" => $quantity, "PRODUCT_XML_ID" => $PRODUCT[ID], "PRICE" => $price, "CURRENCY" => "RUB", "LID" => "s1", "NAME" => $PRODUCT[NAME]);
$basket_id = CSaleBasket::Add($arFields);
$arItem = CSaleBasket::GetByID($basket_id);
if ($arItem["QUANTITY"] != $quantity) {
$arFields = array("QUANTITY" => $arItem["QUANTITY"] + $quantity);
CSaleBasket::Update($basket_id, $arFields);
}
} else {
$basket_id = Add2BasketByProductID($product, $quantity);
}
}
}
break;
case "update":
$arFields = array("QUANTITY" => $_REQUEST["quantity"]);
CSaleBasket::Update($_REQUEST["id"], $arFields);
break;
示例9: array
$arFields["PAY_CALLBACK_FUNC"] = "CatalogPayOrderCallback";
$arFields["PRODUCT_PROVIDER_CLASS"] = "CCatalogProductProvider";
}
if (strlen($arProduct["IBLOCK_EXTERNAL_ID"]) > 0) {
$arFields["CATALOG_XML_ID"] = $arProduct["IBLOCK_EXTERNAL_ID"];
$arFields["PROPS"][] = array("NAME" => "Catalog XML_ID", "CODE" => "CATALOG.XML_ID", "VALUE" => $arProduct["IBLOCK_EXTERNAL_ID"]);
}
if (intVal($arProduct["XML_ID"]) > 0) {
$arFields["PRODUCT_XML_ID"] = $arProduct["XML_ID"];
$arFields["PROPS"][] = array("NAME" => "Product XML_ID", "CODE" => "PRODUCT.XML_ID", "VALUE" => $arProduct["XML_ID"]);
}
$arFuserItems = CSaleUser::GetList(array("USER_ID" => $ID));
if (count($arFuserItems) > 0) {
$arFields["FUSER_ID"] = $arFuserItems["ID"];
}
if (!CSaleBasket::Add($arFields)) {
$viewedError = GetMessage('BUYER_VIEWED_ADD_ERROR');
$viewedMessage = "";
} else {
$viewedMessage = GetMessage('BUYER_VIEWED_MESS_BASKET');
}
}
}
//basket
if (isset($_REQUEST['apply']) && isset($_REQUEST['action']) && $saleModulePermissions >= "W" && check_bitrix_sessid()) {
$arID = array();
$arFields = array();
if ($arFuserItems = CSaleUser::GetList(array("USER_ID" => $ID))) {
$arFields["FUSER_ID"] = $arFuserItems["ID"];
if (!isset($_REQUEST["action_target"]) || $_REQUEST["action_target"] != "selected") {
if (isset($_REQUEST['PRODUCT_ID']) && count($_REQUEST['PRODUCT_ID']) > 0) {
示例10: Add2BasketByProductID
function Add2BasketByProductID($PRODUCT_ID, $QUANTITY = 1, $arRewriteFields = array(), $arProductParams = false)
{
global $APPLICATION;
/* for old use */
if (false === $arProductParams) {
$arProductParams = $arRewriteFields;
$arRewriteFields = array();
}
$PRODUCT_ID = IntVal($PRODUCT_ID);
if ($PRODUCT_ID <= 0) {
$APPLICATION->ThrowException(GetMessage('CATALOG_ERR_EMPTY_PRODUCT_ID'), "EMPTY_PRODUCT_ID");
return false;
}
$QUANTITY = DoubleVal($QUANTITY);
if ($QUANTITY <= 0) {
$QUANTITY = 1;
}
if (!CModule::IncludeModule("sale")) {
$APPLICATION->ThrowException(GetMessage('CATALOG_ERR_NO_SALE_MODULE'), "NO_SALE_MODULE");
return false;
}
if (CModule::IncludeModule("statistic") && IntVal($_SESSION["SESS_SEARCHER_ID"]) > 0) {
$APPLICATION->ThrowException(GetMessage('CATALOG_ERR_SESS_SEARCHER'), "SESS_SEARCHER");
return false;
}
$arProduct = CCatalogProduct::GetByID($PRODUCT_ID);
if ($arProduct === false) {
$APPLICATION->ThrowException(GetMessage('CATALOG_ERR_NO_PRODUCT'), "NO_PRODUCT");
return false;
}
$CALLBACK_FUNC = "CatalogBasketCallback";
$productProviderClass = "CCatalogProductProvider";
//ADD PRODUCT TO SUBSCRIBE
if (isset($arRewriteFields["SUBSCRIBE"]) && $arRewriteFields["SUBSCRIBE"] == "Y") {
global $USER;
if ($USER->IsAuthorized() && !isset($_SESSION["NOTIFY_PRODUCT"][$USER->GetID()])) {
$_SESSION["NOTIFY_PRODUCT"][$USER->GetID()] = array();
}
$arBuyerGroups = CUser::GetUserGroup($USER->GetID());
$arPrice = CCatalogProduct::GetOptimalPrice($PRODUCT_ID, 1, $arBuyerGroups, "N", array(), SITE_ID, array());
$arCallbackPrice = array("PRICE" => $arPrice["DISCOUNT_PRICE"], "VAT_RATE" => 0, "CURRENCY" => CSaleLang::GetLangCurrency(SITE_ID), "QUANTITY" => 1);
} else {
$arRewriteFields["SUBSCRIBE"] = "N";
if ($arProduct["CAN_BUY_ZERO"] != 'Y' && $arProduct["QUANTITY_TRACE"] == "Y" && DoubleVal($arProduct["QUANTITY"]) <= 0) {
$APPLICATION->ThrowException(GetMessage('CATALOG_ERR_PRODUCT_RUN_OUT'), "PRODUCT_RUN_OUT");
return false;
}
$arCallbackPrice = CSaleBasket::ReReadPrice($CALLBACK_FUNC, "catalog", $PRODUCT_ID, $QUANTITY, "N", $productProviderClass);
if (!is_array($arCallbackPrice) || empty($arCallbackPrice)) {
$APPLICATION->ThrowException(GetMessage('CATALOG_PRODUCT_PRICE_NOT_FOUND'), "NO_PRODUCT_PRICE");
return false;
}
}
$dbIBlockElement = CIBlockElement::GetList(array(), array("ID" => $PRODUCT_ID, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "CHECK_PERMISSIONS" => "Y", "MIN_PERMISSION" => "R"), false, false, array("ID", "IBLOCK_ID", "XML_ID", "NAME", "DETAIL_PAGE_URL"));
$arIBlockElement = $dbIBlockElement->GetNext();
if ($arIBlockElement == false) {
$APPLICATION->ThrowException(GetMessage('CATALOG_ERR_NO_IBLOCK_ELEMENT'), "NO_IBLOCK_ELEMENT");
return false;
}
$arProps = array();
$dbIBlock = CIBlock::GetList(array(), array("ID" => $arIBlockElement["IBLOCK_ID"]));
if ($arIBlock = $dbIBlock->Fetch()) {
$arProps[] = array("NAME" => "Catalog XML_ID", "CODE" => "CATALOG.XML_ID", "VALUE" => $arIBlock["XML_ID"]);
}
$arProps[] = array("NAME" => "Product XML_ID", "CODE" => "PRODUCT.XML_ID", "VALUE" => $arIBlockElement["XML_ID"]);
$arPrice = CPrice::GetByID($arCallbackPrice["PRODUCT_PRICE_ID"]);
$arFields = array("PRODUCT_ID" => $PRODUCT_ID, "PRODUCT_PRICE_ID" => $arCallbackPrice["PRODUCT_PRICE_ID"], "PRICE" => $arCallbackPrice["PRICE"], "CURRENCY" => $arCallbackPrice["CURRENCY"], "WEIGHT" => $arProduct["WEIGHT"], "QUANTITY" => $QUANTITY, "LID" => SITE_ID, "DELAY" => "N", "CAN_BUY" => "Y", "NAME" => $arIBlockElement["~NAME"], "MODULE" => "catalog", "PRODUCT_PROVIDER_CLASS" => "CCatalogProductProvider", "NOTES" => $arPrice["CATALOG_GROUP_NAME"], "DETAIL_PAGE_URL" => $arIBlockElement["DETAIL_PAGE_URL"], "CATALOG_XML_ID" => $arIBlock["XML_ID"], "PRODUCT_XML_ID" => $arIBlockElement["XML_ID"], "VAT_RATE" => $arCallbackPrice['VAT_RATE'], "SUBSCRIBE" => $arRewriteFields["SUBSCRIBE"]);
if ($arProduct["CAN_BUY_ZERO"] != "Y" && $arProduct["QUANTITY_TRACE"] == "Y") {
if (IntVal($arProduct["QUANTITY"]) - $QUANTITY < 0) {
$arFields["QUANTITY"] = DoubleVal($arProduct["QUANTITY"]);
}
}
if (is_array($arProductParams) && !empty($arProductParams)) {
foreach ($arProductParams as &$arOneProductParams) {
$arProps[] = array("NAME" => $arOneProductParams["NAME"], "CODE" => $arOneProductParams["CODE"], "VALUE" => $arOneProductParams["VALUE"], "SORT" => $arOneProductParams["SORT"]);
}
if (isset($arOneProductParams)) {
unset($arOneProductParams);
}
}
$arFields["PROPS"] = $arProps;
if (is_array($arRewriteFields) && !empty($arRewriteFields)) {
while (list($key, $value) = each($arRewriteFields)) {
$arFields[$key] = $value;
}
}
$addres = CSaleBasket::Add($arFields);
if ($addres) {
if (isset($arRewriteFields["SUBSCRIBE"]) && $arRewriteFields["SUBSCRIBE"] == "Y") {
$_SESSION["NOTIFY_PRODUCT"][$USER->GetID()][$PRODUCT_ID] = $PRODUCT_ID;
}
if (CModule::IncludeModule("statistic")) {
CStatistic::Set_Event("sale2basket", "catalog", $arFields["DETAIL_PAGE_URL"]);
}
}
return $addres;
}
示例11: Add
/**
* <p>Метод добавляет товар в корзину, если его ещё нет, и обновляет параметры товара с увеличением количества, если он уже находится в корзине. В массиве <b>arFields</b> перечисляются все параметры товара, которые нужны для работы модуля Интернет-магазина (т.е. этот модуль не зависит от других модулей и работает полностью самостоятельно). Метод динамичный.</p> <p>Интернет-магазин не зависит от других модулей, поэтому товары в корзину модуля продаж могут добавляться из любого места (например, из торгового каталога или со статической страницы). Для некоторых модулей существуют функции - оболочки, облегчающие добавление товара в корзину (например, для модуля <b>catalog</b> существуют функции <b>Add2Basket</b> и <b>Add2BasketByProductID</b>). </p>
*
*
* @param array $arFields Ассоциативный массив параметров элемента корзины, содержащий
* следующие ключи: <ul> <li> <b>PRODUCT_ID</b> - уникальный в рамках модуля код
* товара (обязательное поле);</li> <li> <b>PRODUCT_PRICE_ID</b> - ID (идентификатор)
* конкретного ценового предложения товара, пришедшего в корзину.
* Может быть использован в классе <a
* href="http://dev.1c-bitrix.ru/api_help/catalog/classes/cprice/index.php">CPrice</a> модуля Catalog для
* получения детальной информации о цене.</li> <li> <b> PRICE</b> - стоимость
* единицы товара (обязательное поле);</li> <li> <b>CURRENCY</b> - валюта
* стоимости единицы товара (обязательное поле), если валюта
* отличается от базовой валюты для данного сайта, то стоимость
* будет автоматически сконвертирована по текущему курсу;</li> <li>
* <b>WEIGHT</b> - вес единицы товара;</li> <li> <b>QUANTITY</b> - количество единиц
* товара;</li> <li> <b>LID</b> - сайт, на котором сделана покупка
* (обязательное поле);</li> <li> <b>DELAY</b> - флаг "товар отложен" (Y/N);</li> <li>
* <b>CAN_BUY</b> - флаг "товар можно купить" (Y/N) - может устанавливаться
* автоматически про наличии функции обратного вызова для
* поддержки актуальности корзины;</li> <li> <b>NAME</b> - название товара
* (обязательное поле);</li> <li> <b>PRODUCT_XML_ID</b> - внешний код товара
* (необходим при обмене заказами с 1С);</li> <li> <b>CATALOG_XML_ID</b> - внешний
* код каталога (необходим при обмене заказами с 1С);</li> <li> <b>ORDER_ID</b> -
* идентификатор заказа. Ключ будет пустым, если товар еще не
* добавлен в заказ;</li> <li> <b>CALLBACK_FUNC<font color="#FF0000">*</font></b> - название
* функции обратного вызова для поддержки актуальности корзины
* (описание ниже);</li> <li> <b>MODULE</b> - модуль, добавляющий товар в
* корзину;</li> <li> <b>NOTES</b> - особые заметки, например, тип цены;</li> <li>
* <b>ORDER_CALLBACK_FUNC<font color="#FF0000">*</font></b> - название функции обратного
* вызова для оформления заказа (описание ниже);</li> <li> <b>DETAIL_PAGE_URL</b> -
* ссылка на страницу детального просмотра товара;</li> <li>
* <b>CANCEL_CALLBACK_FUNC<font color="#FF0000">*</font></b> - название функции обратного
* вызова для отмены заказа (описание ниже);</li> <li> <b>PAY_CALLBACK_FUNC<font
* color="#FF0000">*</font></b> - название функции обратного вызова, которая
* вызывается при установке флага "Доставка разрешена" заказа;</li> <li>
* <b>FUSER_ID</b> - идентификатор пользователя интернет-магазина,
* необязательный параметр, по умолчанию CSaleBasket::GetBasketUserID() (текущий
* пользователь);</li> <li> <b>DISCOUNT_PRICE</b> - величина скидки;</li> <li>
* <b>DISCOUNT_NAME</b> - название скидки;</li> <li> <b>DISCOUNT_VALUE</b> - размер скидки (в
* процентах);</li> <li> <b>DISCOUNT_COUPON</b> - купон скидки;</li> <li> <b>PROPS</b> - массив
* свойств товара, который сохраняется в корзине. Каждый элемент
* этого массива является массивом следующего формата: <pre
* class="syntax"><code>array("NAME" => "Название свойства", "CODE" => "Код свойства",
* "VALUE" => "Значение свойства", "SORT" => "Индекс сортировки")</code></pre> </li>
* <li> <b>PRODUCT_PROVIDER_CLASS<font color="#0000FF">**</font></b> - содержит имя класса,
* реализующего интерфейс <b> IBXSaleProductProvider</b>. Торговый каталог
* записывает в это поле имя класса <b>CCatalogProductProvider</b>. Если поле
* пусто, то возникает попытка использовать старые поля:<b>CALLBACK_FUNC</b>,
* <b>ORDER_CALLBACK_FUNC</b>, <b>CANCEL_CALLBACK_FUNC</b> и <b>PAY_CALLBACK_FUNC</b>.</li> </ul>
*
* @return int <p>Метод возвращает код элемента корзины, в который попал данный
* товар.</p> <a name="examples"></a>
*
* <h4>Example</h4>
* <pre>
* <?<br>if (CModule::IncludeModule("sale"))<br>{<br> $arFields = array(<br> "PRODUCT_ID" => 51,<br> "PRODUCT_PRICE_ID" => 0,<br> "PRICE" => 138.54,<br> "CURRENCY" => "RUB",<br> "WEIGHT" => 530,<br> "QUANTITY" => 1,<br> "LID" => LANG,<br> "DELAY" => "N",<br> "CAN_BUY" => "Y",<br> "NAME" => "Чемодан кожаный",<br> "CALLBACK_FUNC" => "MyBasketCallback",<br> "MODULE" => "my_module",<br> "NOTES" => "",<br> "ORDER_CALLBACK_FUNC" => "MyBasketOrderCallback",<br> "DETAIL_PAGE_URL" => "/".LANG."/detail.php?ID=51"<br> );<br><br> $arProps = array();<br><br> $arProps[] = array(<br> "NAME" => "Цвет",<br> "CODE" => "color",<br> "VALUE" => "черный"<br> );<br><br> $arProps[] = array(<br> "NAME" => "Размер",<br> "VALUE" => "1.5 x 2.5"<br> );<br><br> $arFields["PROPS"] = $arProps;<br><br> CSaleBasket::Add($arFields);<br>}<br>?><br>
*
*
*
* //пример на проверку создания покупателя
*
* $userId=XXX;//id пользователя
* //получаем FUSER_ID, если покупатель для данного пользователя существует
* $FUSER_ID=CSaleUser::GetList(array('USER_ID' => $userId));
* //если покупателя нет - создаем его
* if(!$FUSER_ID['ID'])
* $FUSER_ID['ID']=CSaleUser::_Add(array("USER_ID" => $userId)); //обратите внимание на нижнее подчеркивание перед Add
* //если не получается создать покупателя - то тут уж ничего не поделаешь
* if(!$FUSER_ID['ID']){
* echo "Error while creating SaleUser";
* die();
* }
* $FUSER_ID=$FUSER_ID['ID'];
* //теперь переменную $FUSER_ID можно использовать для добавления товаров в корзину пользователя с $userId.
*
*
* Смотрите также:
*
* <li><a href="/api_help/catalog/interface.php">Взаимодействие торгового каталога и магазина</a></li>
* </pre>
*
*
* @static
* @link http://dev.1c-bitrix.ru/api_help/sale/classes/csalebasket/csalebasket__add.php
* @author Bitrix
*/
public static function Add($arFields)
{
global $DB, $APPLICATION;
if (isset($arFields["ID"])) {
unset($arFields["ID"]);
}
$isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'N');
CSaleBasket::Init();
if (!CSaleBasket::CheckFields("ADD", $arFields)) {
return false;
}
if (!array_key_exists('IGNORE_CALLBACK_FUNC', $arFields) || 'Y' != $arFields['IGNORE_CALLBACK_FUNC']) {
if (array_key_exists("CALLBACK_FUNC", $arFields) && !empty($arFields["CALLBACK_FUNC"]) || array_key_exists("PRODUCT_PROVIDER_CLASS", $arFields) && !empty($arFields["PRODUCT_PROVIDER_CLASS"])) {
//.........这里部分代码省略.........
示例12: SubscribeProduct
//.........这里部分代码省略.........
'PRODUCT_PRICE_ID' => 0,
'CATALOG_GROUP_NAME' => '',
);
$arBuyerGroups = $USER->GetUserGroupArray();
$arSubscrPrice = CCatalogProduct::GetOptimalPrice($intProductID, 1, $arBuyerGroups, "N", array(), SITE_ID, array());
if (!empty($arSubscrPrice) && is_array($arSubscrPrice))
{
$arPrice['PRICE'] = $arSubscrPrice['DISCOUNT_PRICE'];
$arPrice['CURRENCY'] = CCurrency::GetBaseCurrency();
$arPrice['VAT_RATE'] = $arSubscrPrice['PRICE']['VAT_RATE'];
$arPrice['PRODUCT_PRICE_ID'] = $arSubscrPrice["PRICE"]["ID"];
$arPrice['CATALOG_GROUP_NAME'] = $arSubscrPrice["PRICE"]["CATALOG_GROUP_NAME"];
}
$arProps = array();
$strIBlockXmlID = strval(CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], 'XML_ID'));
if ('' != $strIBlockXmlID)
{
$arProps[] = array(
"NAME" => "Catalog XML_ID",
"CODE" => "CATALOG.XML_ID",
"VALUE" => $strIBlockXmlID
);
}
$arProps[] = array(
"NAME" => "Product XML_ID",
"CODE" => "PRODUCT.XML_ID",
"VALUE" => $arProduct["XML_ID"]
);
if (!empty($arProductParams) && is_array($arProductParams))
{
foreach ($arProductParams as &$arOneProductParams)
{
$arProps[] = array(
"NAME" => $arOneProductParams["NAME"],
"CODE" => $arOneProductParams["CODE"],
"VALUE" => $arOneProductParams["VALUE"],
"SORT" => $arOneProductParams["SORT"],
);
}
if (isset($arOneProductParams))
unset($arOneProductParams);
}
$arFields = array(
"PRODUCT_ID" => $intProductID,
"PRODUCT_PRICE_ID" => $arPrice['PRODUCT_PRICE_ID'],
"PRICE" => $arPrice['PRICE'],
"CURRENCY" => $arPrice['CURRENCY'],
"WEIGHT" => $arCatalogProduct["WEIGHT"],
"QUANTITY" => 1,
"LID" => SITE_ID,
"DELAY" => "N",
"CAN_BUY" => "N",
"SUBSCRIBE" => "Y",
"NAME" => $arProduct["NAME"],
"MODULE" => "catalog",
"PRODUCT_PROVIDER_CLASS" => "CCatalogProductProvider",
"NOTES" => $arPrice["CATALOG_GROUP_NAME"],
"DETAIL_PAGE_URL" => $arProduct["DETAIL_PAGE_URL"],
"CATALOG_XML_ID" => $strIBlockXmlID,
"PRODUCT_XML_ID" => $arProduct["XML_ID"],
"PROPS" => $arProps,
);
if (!empty($arRewriteFields) && is_array($arRewriteFields))
{
if (array_key_exists('SUBSCRIBE', $arRewriteFields))
unset($arRewriteFields['SUBSCRIBE']);
if (array_key_exists('CAN_BUY', $arRewriteFields))
unset($arRewriteFields['CAN_BUY']);
if (array_key_exists('DELAY', $arRewriteFields))
unset($arRewriteFields['DELAY']);
if (!empty($arRewriteFields))
$arFields = array_merge($arFields, $arRewriteFields);
}
$mxBasketID = CSaleBasket::Add($arFields);
if ($mxBasketID)
{
if (!array_key_exists('NOTIFY_PRODUCT', $_SESSION))
{
$_SESSION['NOTIFY_PRODUCT'] = array(
$intUserID = array(),
);
}
elseif (!array_key_exists($intUserID, $_SESSION['NOTIFY_PRODUCT']))
{
$_SESSION['NOTIFY_PRODUCT'][$intUserID] = array();
}
$_SESSION["NOTIFY_PRODUCT"][$intUserID][$intProductID] = $intProductID;
if (CModule::IncludeModule("statistic"))
CStatistic::Set_Event("sale2basket", "subscribe", $intProductID);
}
return $mxBasketID;
}
示例13: __MakeOrder
function __MakeOrder($prdCnt = 1, $arData = array())
{
global $APPLICATION, $USER, $DB;
CModule::IncludeModule("iblock");
CModule::IncludeModule("sale");
CModule::IncludeModule("catalog");
$arPrd = array();
$dbItem = CIBlockElement::GetList(array(), array("IBLOCK_TYPE" => "offers", "IBLOCK_SITE_ID" => WIZARD_SITE_ID, "PROPERTY_NEWPRODUCT" => false), false, array("nTopCount" => 100), array("ID", "IBLOCK_ID", "XML_ID", "NAME", "DETAIL_PAGE_URL", "IBLOCK_XML_ID"));
while ($arItem = $dbItem->GetNext()) {
$arPrd[] = $arItem;
}
if (!empty($arPrd)) {
$arOrder = array("LID" => $arData["SITE_ID"], "PERSON_TYPE_ID" => $arData["PERSON_TYPE_ID"], "PAYED" => "N", "CANCELED" => "N", "STATUS_ID" => "N", "PRICE" => 1, "CURRENCY" => $arData["CURRENCY"], "USER_ID" => $arData["USER_ID"], "PAY_SYSTEM_ID" => $arData["PAY_SYSTEM_ID"]);
$fuserID = 0;
$dbFUserListTmp = CSaleUser::GetList(array("USER_ID" => $arData["USER_ID"]));
if (empty($dbFUserListTmp)) {
$arFields = array("=DATE_INSERT" => $DB->GetNowFunction(), "=DATE_UPDATE" => $DB->GetNowFunction(), "USER_ID" => $arData["USER_ID"]);
$fuserID = CSaleUser::_Add($arFields);
} else {
$fuserID = $dbFUserListTmp['ID'];
}
$orderID = CSaleOrder::Add($arOrder);
CCatalogProduct::setPriceVatIncludeMode(true);
CCatalogProduct::setUsedCurrency(CSaleLang::GetLangCurrency(WIZARD_SITE_ID));
CCatalogProduct::setUseDiscount(true);
for ($i = 0; $i < $prdCnt; $i++) {
$prdID = $arPrd[mt_rand(20, 99)];
$arProduct = CCatalogProduct::GetByID($prdID["ID"]);
$arPrice = CCatalogProduct::GetOptimalPrice($prdID["ID"], 1, array(2), 'N', array(), WIZARD_SITE_ID, array());
$arFields = array("IGNORE_CALLBACK_FUNC" => "Y", "PRODUCT_ID" => $prdID["ID"], "PRODUCT_PRICE_ID" => $arPrice['PRICE']['ID'], "BASE_PRICE" => $arPrice['RESULT_PRICE']['BASE_PRICE'], "PRICE" => $arPrice['RESULT_PRICE']['DISCOUNT_PRICE'], "VAT_RATE" => $arPrice['PRICE']['VAT_RATE'], "CURRENCY" => $arPrice['RESULT_PRICE']['CURRENCY'], "WEIGHT" => $arProduct["WEIGHT"], "DIMENSIONS" => serialize(array("WIDTH" => $arProduct["WIDTH"], "HEIGHT" => $arProduct["HEIGHT"], "LENGTH" => $arProduct["LENGTH"])), "QUANTITY" => 1, "LID" => WIZARD_SITE_ID, "DELAY" => "N", "CAN_BUY" => "Y", "NAME" => $prdID["NAME"], "CALLBACK_FUNC" => "", "MODULE" => "catalog", "PRODUCT_PROVIDER_CLASS" => "CCatalogProductProvider", "ORDER_CALLBACK_FUNC" => "", "CANCEL_CALLBACK_FUNC" => "", "PAY_CALLBACK_FUNC" => "", "DETAIL_PAGE_URL" => $prdID["DETAIL_PAGE_URL"], "CATALOG_XML_ID" => $prdID["IBLOCK_XML_ID"], "PRODUCT_XML_ID" => $prdID["XML_ID"], "NOTES" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"], "FUSER_ID" => $fuserID, "ORDER_ID" => $orderID);
$addres = CSaleBasket::Add($arFields);
}
$dbBasketItems = CSaleBasket::GetList(array(), array("ORDER_ID" => $orderID), false, false, array("ID", "QUANTITY", "PRICE"));
$ORDER_PRICE = 0;
while ($arBasketItems = $dbBasketItems->GetNext()) {
$ORDER_PRICE += roundEx($arBasketItems["PRICE"], SALE_VALUE_PRECISION) * DoubleVal($arBasketItems["QUANTITY"]);
}
$totalOrderPrice = $ORDER_PRICE + $arData["PRICE_DELIVERY"];
CSaleOrder::Update($orderID, array("PRICE" => $totalOrderPrice));
foreach ($arData["PROPS"] as $val) {
$arFields = array("ORDER_ID" => $orderID, "ORDER_PROPS_ID" => $val["ID"], "NAME" => $val["NAME"], "CODE" => $val["CODE"], "VALUE" => $val["VALUE"]);
CSaleOrderPropsValue::Add($arFields);
}
return $orderID;
}
}
示例14: DoSaveOrderBasket
static function DoSaveOrderBasket($orderId, $siteId, $userId, &$arShoppingCart, &$arErrors, $arCoupons = array(), $arStoreBarcodeOrderFormData = array(), $bSaveBarcodes = false)
{
global $DB;
if (defined("SALE_DEBUG") && SALE_DEBUG) {
CSaleHelper::WriteToLog("DoSaveOrderBasket - Started", array("orderId" => $orderId, "siteId" => $siteId, "userId" => $userId, "bSaveBarcodes" => $bSaveBarcodes, "arStoreBarcodeOrderFormData" => $arStoreBarcodeOrderFormData), "DSOB1");
}
$orderId = IntVal($orderId);
if ($orderId <= 0) {
return false;
}
if (!is_array($arShoppingCart) || count($arShoppingCart) <= 0) {
$arErrors[] = array("CODE" => "PARAM", "TEXT" => GetMessage('SKGB_SHOPPING_CART_EMPTY'));
return false;
}
$isOrderReserved = false;
$isOrderDeducted = false;
$dbOrderTmp = CSaleOrder::GetList(array(), array("ID" => $orderId), false, false, array("ID", "RESERVED", "DEDUCTED"));
if ($arOrder = $dbOrderTmp->Fetch()) {
if ($arOrder["RESERVED"] == "Y") {
$isOrderReserved = true;
}
if ($arOrder["DEDUCTED"] == "Y") {
$isOrderDeducted = true;
}
}
$arOldItems = array();
$dbResult = CSaleBasket::GetList(array(), array("ORDER_ID" => $orderId), false, false, array("ID", "QUANTITY", "CANCEL_CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "PRODUCT_PROVIDER_CLASS", "RESERVED", "RESERVE_QUANTITY"));
while ($arResult = $dbResult->Fetch()) {
$arOldItems[$arResult["ID"]] = array("QUANTITY" => $arResult["QUANTITY"], "CANCEL_CALLBACK_FUNC" => $arResult["CANCEL_CALLBACK_FUNC"], "PRODUCT_PROVIDER_CLASS" => $arResult["PRODUCT_PROVIDER_CLASS"], "MODULE" => $arResult["MODULE"], "PRODUCT_ID" => $arResult["PRODUCT_ID"], "RESERVED" => $arResult["RESERVED"], "RESERVE_QUANTITY" => $arResult["RESERVE_QUANTITY"]);
}
if (is_array($arCoupons) && count($arCoupons) > 0) {
foreach (GetModuleEvents("sale", "OnSetCouponList", true) as $arEvent) {
ExecuteModuleEventEx($arEvent, array($userId, $arCoupons, array()));
}
}
$FUSER_ID = 0;
$arFUserListTmp = CSaleUser::GetList(array("USER_ID" => $userId));
if (empty($arFUserListTmp)) {
$arFields = array("=DATE_INSERT" => $DB->GetNowFunction(), "=DATE_UPDATE" => $DB->GetNowFunction(), "USER_ID" => $userId);
$FUSER_ID = CSaleUser::_Add($arFields);
} else {
$FUSER_ID = $arFUserListTmp["ID"];
}
foreach ($arShoppingCart as $id => &$arItem) {
if (defined("SALE_DEBUG") && SALE_DEBUG) {
CSaleHelper::WriteToLog("DoSaveOrderBasket - Item", array("arItem" => $arItem), "DSOB2");
}
if (array_key_exists("ID", $arItem) && intval($arItem["ID"]) > 0) {
$arItem["ID"] = intval($arItem["ID"]);
if (defined("SALE_DEBUG") && SALE_DEBUG) {
CSaleHelper::WriteToLog("DoSaveOrderBasket - Product #" . $arItem["ID"] . " already in the basket", array(), "DSOB3");
}
//product already in the basket, change quantity
if (array_key_exists($arItem["ID"], $arOldItems)) {
if ($arOldItems[$arItem["ID"]]["QUANTITY"] - $arItem["QUANTITY"] != 0) {
self::DoChangeProductQuantity($arItem, $arItem["QUANTITY"] - $arOldItems[$arItem["ID"]]["QUANTITY"], $isOrderReserved, $isOrderDeducted, $arStoreBarcodeOrderFormData[$arItem["ID"]], array("ORDER_ID" => $orderId, "USER_ID" => $userId, "SITE_ID" => $siteId));
}
unset($arOldItems[$arItem["ID"]]);
} else {
if ($arItem["QUANTITY"] != 0) {
self::DoChangeProductQuantity($arItem, $arItem["QUANTITY"], $isOrderReserved, $isOrderDeducted, $arStoreBarcodeOrderFormData[$arItem["ID"]], array("ORDER_ID" => $orderId, "USER_ID" => $userId, "SITE_ID" => $siteId));
}
}
$arFuserItems = CSaleUser::GetList(array("USER_ID" => intval($userId)));
$arItem["FUSER_ID"] = $arFuserItems["ID"];
//CSaleBasket::Update($arItem["ID"], array("CALLBACK_FUNC" => false, "ORDER_ID" => $orderId, "IGNORE_CALLBACK_FUNC" => "Y") + $arItem);
CSaleBasket::Update($arItem["ID"], array("ORDER_ID" => $orderId, "IGNORE_CALLBACK_FUNC" => "Y") + $arItem);
} else {
if (defined("SALE_DEBUG") && SALE_DEBUG) {
CSaleHelper::WriteToLog("DoSaveOrderBasket - new product in the basket", array(), "DSOB3");
}
unset($arItem["ID"]);
/** @var $productProvider IBXSaleProductProvider */
if ($productProvider = CSaleBasket::GetProductProvider($arItem)) {
$arItem["ID"] = CSaleBasket::Add(array("ORDER_ID" => $orderId, "IGNORE_CALLBACK_FUNC" => "Y") + $arItem);
if ($bSaveBarcodes) {
if ($arItem["BARCODE_MULTI"] == "N") {
foreach ($arItem["STORES"] as $key => $arStore) {
$arStoreBarcodeFields = array("BASKET_ID" => $arItem["ID"], "BARCODE" => "", "STORE_ID" => $arStore["STORE_ID"], "QUANTITY" => $arStore["QUANTITY"], "CREATED_BY" => intval($GLOBALS["USER"]->GetID()) > 0 ? IntVal($GLOBALS["USER"]->GetID()) : "", "MODIFIED_BY" => intval($GLOBALS["USER"]->GetID()) > 0 ? IntVal($GLOBALS["USER"]->GetID()) : "");
CSaleStoreBarcode::Add($arStoreBarcodeFields);
}
} else {
if (is_array($arItem["STORES"]) && count($arItem["STORES"]) > 0) {
foreach ($arItem["STORES"] as $key => $arStore) {
if (isset($arStore["BARCODE"]) && isset($arStore["BARCODE_FOUND"])) {
foreach ($arStore["BARCODE"] as $barcodeId => $barcodeValue) {
// save only non-empty and valid barcodes TODO - if errors?
if (strlen($barcodeValue) > 0 && $arStore["BARCODE_FOUND"][$barcodeId] == "Y") {
$arStoreBarcodeFields = array("BASKET_ID" => $arItem["ID"], "BARCODE" => $barcodeValue, "STORE_ID" => $arStore["STORE_ID"], "QUANTITY" => 1, "CREATED_BY" => intval($GLOBALS["USER"]->GetID()) > 0 ? IntVal($GLOBALS["USER"]->GetID()) : "", "MODIFIED_BY" => intval($GLOBALS["USER"]->GetID()) > 0 ? IntVal($GLOBALS["USER"]->GetID()) : "");
CSaleStoreBarcode::Add($arStoreBarcodeFields);
}
}
}
}
}
}
}
if ($arItem["QUANTITY"] != 0) {
self::DoChangeProductQuantity($arItem, $arItem["QUANTITY"], $isOrderReserved, $isOrderDeducted, $arStoreBarcodeOrderFormData[$id], array("ORDER_ID" => $orderId, "USER_ID" => $userId, "SITE_ID" => $siteId));
}
//.........这里部分代码省略.........
示例15: elseif
$res = CSaleBasket::Update($arBasketList[$i][$j]["ID"], $arFields);
if ($arOldBasketList[$arBasketList[$i][$j]["ID"]]["QUANTITY"] > $arFields["QUANTITY"]) {
if (strlen($arFields["CANCEL_CALLBACK_FUNC"]) > 0) {
$arFields = CSaleBasket::ExecuteCallbackFunction($arFields["CANCEL_CALLBACK_FUNC"], $arFields["MODULE"], $arFields["PRODUCT_ID"], $arOldBasketList[$arBasketList[$i][$j]["ID"]]["QUANTITY"] - $arFields["QUANTITY"], true);
}
} elseif ($arOldBasketList[$arBasketList[$i][$j]["ID"]]["QUANTITY"] < $arFields["QUANTITY"]) {
if (strlen($arFields["ORDER_CALLBACK_FUNC"]) > 0) {
$arFields = CSaleBasket::ExecuteCallbackFunction($arFields["ORDER_CALLBACK_FUNC"], $arFields["MODULE"], $arFields["PRODUCT_ID"], $arFields["QUANTITY"] - $arOldBasketList[$arBasketList[$i][$j]["ID"]]["QUANTITY"]);
}
}
unset($arOldBasketList[$arBasketList[$i][$j]["ID"]]);
} else {
$errorMessage .= GetMessage("SOE_INTERNAL_RFITH67") . ". ";
}
} else {
$res = CSaleBasket::Add($arFields) > 0;
if (strlen($arFields["ORDER_CALLBACK_FUNC"]) > 0) {
$arFields = CSaleBasket::ExecuteCallbackFunction($arFields["ORDER_CALLBACK_FUNC"], $arFields["MODULE"], $arFields["PRODUCT_ID"], $arFields["QUANTITY"]);
}
}
if (!$res) {
if ($ex = $APPLICATION->GetException()) {
$errorMessage .= $ex->GetString();
} else {
$errorMessage .= str_replace("#ID#", $arBasketList[$i][$j]["PRODUCT_ID"], GetMessage("SOE_ERROR_SAVE_ITEM")) . ". ";
}
}
}
}
foreach ($arOldBasketList as $key => $value) {
if (strlen($value["CANCEL_CALLBACK_FUNC"]) > 0) {