/** * Transfers basket from one user to another one * * @param integer $from * @param integer $to * @global object $DB * @return boolean */ public static function transferBasket($from, $to) { global $DB; $from = intval($from); $to = intval($to); CModule::IncludeModule('sale'); if ($to > 0 && CSaleUser::GetList(array("ID" => $to))) { $deleteQuery = "DELETE FROM b_sale_basket WHERE FUSER_ID = " . $to . " "; $updateQuery = "UPDATE b_sale_basket SET " . " FUSER_ID = " . $to . " " . "WHERE FUSER_ID = " . $from . " "; $DB->Query($deleteQuery, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $DB->Query($updateQuery, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); return true; } return false; }
if (!isset($str_TAX_VALUE) OR $str_TAX_VALUE == "") $str_TAX_VALUE = 0; if (intval($str_PERSON_TYPE_ID) <= 0) { $str_PERSON_TYPE_ID = 0; $arFilter = array(); $arFilter["ACTIVE"] = "Y"; if(strlen($LID) > 0) $arFilter["LID"] = $LID; $dbPersonType = CSalePersonType::GetList(array("SORT" => "ASC", "NAME" => "ASC"), $arFilter, false, array('nTopCount' => 1), array('ID')); if($arPersonType = $dbPersonType->Fetch()) $str_PERSON_TYPE_ID = $arPersonType["ID"]; } $arFuserItems = CSaleUser::GetList(array("USER_ID" => intval($str_USER_ID))); $FUSER_ID = $arFuserItems["ID"]; /* * form select site */ if ((!isset($LID) OR $LID == "") AND (defined('BX_PUBLIC_MODE') OR BX_PUBLIC_MODE == 1) ) { $arSitesShop = array(); $arSitesTmp = array(); $rsSites = CSite::GetList($by="id", $order="asc", array("ACTIVE" => "Y")); while ($arSite = $rsSites->Fetch()) { $site = COption::GetOptionString("sale", "SHOP_SITE_".$arSite["ID"], ""); if ($arSite["ID"] == $site) {
$arRecommendedResult = CSaleProduct::GetRecommendetProduct($arOrder["USER_ID"], $arOrder["LID"], $arFilterRecomendet); $recomCnt = count($arRecommendedResult); if ($recomCnt > 2) { $arTmp = array(); $arTmp[] = $arRecommendedResult[0]; $arTmp[] = $arRecommendedResult[1]; $arRecommendedResult = $arTmp; } if ($recomCnt <= 0) $displayNone = "none"; $arErrors = array(); $arFuserItems = CSaleUser::GetList(array("USER_ID" => intval($arOrder["USER_ID"]))); $arCartWithoutSetItems = array(); $arTmpShoppingCart = CSaleBasket::DoGetUserShoppingCart($arOrder["LID"], $arOrder["USER_ID"], $arFuserItems["ID"], $arErrors, array()); if (is_array($arTmpShoppingCart)) { foreach ($arTmpShoppingCart as $arCartItem) { if (CSaleBasketHelper::isSetItem($arCartItem)) continue; $arCartWithoutSetItems[] = $arCartItem; } } $basketCnt = count($arCartWithoutSetItems); if ($basketCnt > 2)
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"], ); CSaleOrderPropsValue::Add($arFields); } return $orderID; } }
function OnUserDelete($userID) { if ($userID <= 0) { return false; } $arSUser = CSaleUser::GetList(array("USER_ID" => $userID)); if (!empty($arSUser)) { if (!CSaleBasket::DeleteAll($arSUser["ID"])) { return false; } if (!CSaleUser::Delete($arSUser["ID"])) { return false; } } return true; }
/** * <p>Метод осуществляет продление подписки с кодом ID.</p> <p><b>Примечание</b>. Метод использует внутреннюю транзакцию. Если у вас используется <b>MySQL</b> и <b>InnoDB</b>, и ранее была открыта транзакция, то ее необходимо закрыть до подключения метода.</p> * * * * * @param int $ID Код записи с информацией о продлении. * * * * @return bool <p>Метод возвращает <i>true</i> в случае успешного продления или <i>false</i> * в случае ошибки.</p><br><br> * * @static * @link http://dev.1c-bitrix.ru/api_help/sale/classes/csalerecurring/csalerecurring.nextpayment.php * @author Bitrix */ public static function NextPayment($ID) { global $DB; global $USER; $ID = IntVal($ID); if ($ID <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGR_NO_RECID"), "NO_RECORD_ID"); return False; } $arRecur = CSaleRecurring::GetByID($ID); if (!$arRecur) { $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $ID, GetMessage("SKGR_NO_RECID1")), "NO_RECORD"); return False; } $arOrder = CSaleOrder::GetByID($arRecur["ORDER_ID"]); if (!$arOrder) { $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arRecur["ORDER_ID"], GetMessage("SKGR_NO_ORDER1")), "NO_ORDER"); return False; } $bSuccess = True; $newOrderID = IntVal($arRecur["ORDER_ID"]); /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider($arRecur)) { $arProduct = $productProvider::RecurringOrderProduct(array( "PRODUCT_ID" => $arRecur["PRODUCT_ID"], "USER_ID" => $arOrder["USER_ID"] )); } else { $arProduct = CSaleRecurring::ExecuteCallbackFunction( $arRecur["CALLBACK_FUNC"], $arRecur["MODULE"], $arRecur["PRODUCT_ID"], $arOrder["USER_ID"] ); } if (!$arProduct || !is_array($arProduct) || count($arProduct) <= 0) { CSaleRecurring::CancelRecurring($arRecur["ID"], "Y", "Product is not found"); /* $arFields = array( "CANCELED" => "Y", "DATE_CANCELED" => Date(CDatabase::DateFormatToPHP(CLang::GetDateFormat("FULL", LANG))), "CANCELED_REASON" => "Product is not found" ); CSaleRecurring::Update($arRecur["ID"], $arFields); */ //CSaleRecurring::Delete($arRecur["ID"]); return True; } if ($arProduct["WITHOUT_ORDER"] == "Y" || $arRecur["SUCCESS_PAYMENT"] == "Y") { $baseSiteCurrency = CSaleLang::GetLangCurrency($arOrder["LID"]); $productPrice = roundEx(CCurrencyRates::ConvertCurrency($arProduct["PRICE"], $arProduct["CURRENCY"], $baseSiteCurrency), SALE_VALUE_PRECISION); // Delivery $deliveryPrice = 0; $deliveryID = 0; $arOrder["DELIVERY_ID"] = IntVal($arOrder["DELIVERY_ID"]); if ($arOrder["DELIVERY_ID"] > 0) { $deliveryLocation = 0; $dbOrderPropValues = CSaleOrderPropsValue::GetList( array(), array( "ORDER_ID" => $arRecur["ORDER_ID"], "PROP_IS_LOCATION" => "Y" ), false, false, array("VALUE") ); if ($arOrderPropValues = $dbOrderPropValues->Fetch()) $deliveryLocation = IntVal($arOrderPropValues["VALUE"]); $dbDelivery = CSaleDelivery::GetList( array("SORT" => "ASC", "NAME" => "ASC"), array( "LID" => $arOrder["LID"], "WEIGHT" => DoubleVal($arProduct["WEIGHT"]) * DoubleVal($arProduct["QUANTITY"]), // Changed by Sigurd, 2007-08-16 "ORDER_PRICE" => $productPrice * DoubleVal($arProduct["QUANTITY"]), "ACTIVE" => "Y", "LOCATION" => $deliveryLocation ) ); while ($arDelivery = $dbDelivery->Fetch()) { $deliveryPriceTmp = roundEx(CCurrencyRates::ConvertCurrency($arDelivery["PRICE"], $arDelivery["CURRENCY"], $baseSiteCurrency), SALE_VALUE_PRECISION); if (IntVal($arDelivery["ID"]) == $arOrder["DELIVERY_ID"]) { $deliveryID = IntVal($arDelivery["ID"]); $deliveryPrice = $deliveryPriceTmp; break; } if ($deliveryPriceTmp < $deliveryPrice || $deliveryID <= 0) { $deliveryID = IntVal($arDelivery["ID"]); $deliveryPrice = $deliveryPriceTmp; } } if ($deliveryID <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGR_NO_DELIVERY"), "NO_DELIVERY"); return False; } } // Sale discounts $discount = 0; $discountPrice = $productPrice; $discountProduct = 0; $dbDiscount = CSaleDiscount::GetList( array("SORT" => "ASC"), array( "LID" => $arOrder["LID"], "ACTIVE" => "Y", "!>ACTIVE_FROM" => Date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL"))), "!<ACTIVE_TO" => Date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL"))), "<=PRICE_FROM" => $productPrice, ">=PRICE_TO" => $productPrice, "USER_GROUPS" => $USER->GetUserGroup($arOrder['USER_ID']), ) ); if ($arDiscount = $dbDiscount->Fetch()) { if ($arDiscount["DISCOUNT_TYPE"] == "P") { $discountProduct = roundEx($productPrice * $arDiscount["DISCOUNT_VALUE"] / 100, SALE_VALUE_PRECISION); $discount = roundEx($discountProduct * DoubleVal($arProduct["QUANTITY"]), SALE_VALUE_PRECISION); // Changed by Sigurd, 2007-08-16 $discountPrice = $productPrice - $discountProduct; } else { $discountValue = CCurrencyRates::ConvertCurrency($arDiscount["DISCOUNT_VALUE"], $arDiscount["CURRENCY"], $baseSiteCurrency); $discountValue = roundEx($discountValue, SALE_VALUE_PRECISION); $discountProduct = roundEx(1.0 * $discountValue / DoubleVal($arProduct["QUANTITY"]), SALE_VALUE_PRECISION);// Changed by Sigurd, 2007-08-16 $discount = roundEx($curDiscount * DoubleVal($arProduct["QUANTITY"]), SALE_VALUE_PRECISION); $discountPrice = $productPrice - $discountProduct; } } $bUseVat = false; $vatRate = 0; if(DoubleVal($arProduct["VAT_RATE"]) > 0) { $bUseVat = true; $vatRate = $arProduct["VAT_RATE"]; } // Tax $arTaxExempt = array(); $dbUserGroups = CUser::GetUserGroupEx($arOrder["USER_ID"]); while ($arUserGroups = $dbUserGroups->Fetch()) { $dbTaxExemptTmp = CSaleTax::GetExemptList(array("GROUP_ID" => $arUserGroups["GROUP_ID"])); while ($arTaxExemptTmp = $dbTaxExemptTmp->Fetch()) { $arTaxExemptTmp["TAX_ID"] = IntVal($arTaxExemptTmp["TAX_ID"]); if (!in_array($arTaxExemptTmp["TAX_ID"], $arTaxExempt)) $arTaxExempt[] = $arTaxExemptTmp["TAX_ID"]; } } $taxPrice = 0; $taxVatPrice = 0; if(!$bUseVat) { $taxLocation = 0; $dbOrderPropValues = CSaleOrderPropsValue::GetList( array(), array( "ORDER_ID" => $arRecur["ORDER_ID"], "PROP_IS_LOCATION4TAX" => "Y" ), false, false, array("VALUE") ); if ($arOrderPropValues = $dbOrderPropValues->Fetch()) $taxLocation = IntVal($arOrderPropValues["VALUE"]); $arTaxList = array(); $dbTaxRateTmp = CSaleTaxRate::GetList( array("APPLY_ORDER" => "ASC"), array( "LID" => $arOrder["LID"], "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"], "ACTIVE" => "Y", "LOCATION" => $taxLocation ) ); while ($arTaxRateTmp = $dbTaxRateTmp->Fetch()) { if (!in_array(IntVal($arTaxRateTmp["TAX_ID"]), $arTaxExempt)) { $arTaxList[] = $arTaxRateTmp; } } } else { $arTaxList[] = Array( "ID" => 0, "TAX_NAME" => GetMessage("SKGR_VAT"), "IS_PERCENT" => "Y", "VALUE" => $vatRate*100, "VALUE_MONEY" => 0, "APPLY_ORDER" => 100, "IS_IN_PRICE" => "Y", "CODE" => "VAT" ); } $arTaxSums = array(); if (!empty($arTaxList)) { if(!$bUseVat) { $taxPriceTmp = CSaleOrderTax::CountTaxes( $discountPrice * DoubleVal($arProduct["QUANTITY"]), $arTaxList, $baseSiteCurrency ); for ($di = 0, $intCount = count($arTaxList); $di < $intCount; $di++) { $arTaxList[$di]["VALUE_MONEY"] += $arTaxList[$di]["TAX_VAL"]; } for ($di = 0, $intCount = count($arTaxList); $di < $intCount; $di++) { $arTaxSums[$arTaxList[$di]["TAX_ID"]]["VALUE"] = $arTaxList[$di]["VALUE_MONEY"]; $arTaxSums[$arTaxList[$di]["TAX_ID"]]["NAME"] = $arTaxList[$di]["NAME"]; if ($arTaxList[$di]["IS_IN_PRICE"] != "Y") { $taxPrice += $arTaxList[$di]["VALUE_MONEY"]; } } } else { $arTaxList[0]["VALUE_MONEY"] = (($discountPrice / ($vatRate +1)) * $vatRate) * DoubleVal($arProduct["QUANTITY"]); $taxVatPrice = $arTaxList[0]["VALUE_MONEY"]; } } // Changed by Sigurd, 2007-08-16 $totalOrderPrice = $discountPrice * DoubleVal($arProduct["QUANTITY"]) + $deliveryPrice + $taxPrice; $arProduct["WITHOUT_ORDER"] = (($arProduct["WITHOUT_ORDER"]=="Y") ? "Y" : "N"); if ($arProduct["WITHOUT_ORDER"] == "N") { $DB->StartTransaction(); // Saving $arSaleUser = CSaleUser::GetList(Array(), Array("USER_ID" => $arOrder["USER_ID"])); if(!empty($arSaleUser)) { $currentFUser = $arSaleUser["ID"]; } else { $currentFUser = CSaleUser::_Add( array( "=DATE_INSERT" => $DB->GetNowFunction(), "=DATE_UPDATE" => $DB->GetNowFunction(), "USER_ID" => $arOrder["USER_ID"] ) ); } $arFields = array( "FUSER_ID" => $currentFUser, "PRODUCT_ID" => $arProduct["PRODUCT_ID"], "PRODUCT_NAME" => $arProduct["PRODUCT_NAME"], "PRODUCT_URL" => $arProduct["PRODUCT_URL"], "PRODUCT_PRICE_ID" => $arProduct["PRODUCT_PRICE_ID"], "PRICE" => $arProduct["PRICE"], "CURRENCY" => $arProduct["CURRENCY"], "WEIGHT" => $arProduct["WEIGHT"], "QUANTITY" => $arProduct["QUANTITY"], "LID" => $arOrder["LID"], "DELAY" => "N", "CAN_BUY" => "Y", "NAME" => $arProduct["NAME"], "CALLBACK_FUNC" => $arProduct["CALLBACK_FUNC"], "ORDER_CALLBACK_FUNC" => $arProduct["ORDER_CALLBACK_FUNC"], "CANCEL_CALLBACK_FUNC" => $arProduct["CANCEL_CALLBACK_FUNC"], "PAY_CALLBACK_FUNC" => $arProduct["PAY_CALLBACK_FUNC"], "PRODUCT_PROVIDER_CLASS" => $arProduct["PRODUCT_PROVIDER_CLASS"], "MODULE" => $arRecur["MODULE"], "NOTES" => $arProduct["CATALOG_GROUP_NAME"], "DETAIL_PAGE_URL" => $arProduct["DETAIL_PAGE_URL"], "VATE_RATE" => $arProduct["VATE_RATE"], "PRODUCT_XML_ID" => $arProduct["PRODUCT_XML_ID"], "RENEWAL" => "Y" ); $basketID = CSaleBasket::Add($arFields); $basketID = IntVal($basketID); if ($basketID <= 0) $bSuccess = False; if ($bSuccess) { if (CModule::IncludeModule("statistic")) CStatistic::Set_Event("eStore", "add2basket", $arFields["PRODUCT_ID"]); $arFields = array( "LID" => $arOrder["LID"], "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"], "PAYED" => "N", "CANCELED" => "N", "STATUS_ID" => "N", "PRICE_DELIVERY" => $deliveryPrice, "ALLOW_DELIVERY" => "N", "PRICE" => $totalOrderPrice, "CURRENCY" => $baseSiteCurrency, "DISCOUNT_VALUE" => $discount, "USER_ID" => $arOrder["USER_ID"], "PAY_SYSTEM_ID" => $arOrder["PAY_SYSTEM_ID"], "DELIVERY_ID" => $deliveryID, "USER_DESCRIPTION" => $arOrder["USER_DESCRIPTION"], "TAX_VALUE" => (($bUseVat)? $taxVatPrice : $taxPrice), "STAT_GID" => $arOrder["STAT_GID"], "RECURRING_ID" => $arRecur["ID"] ); $newOrderID = CSaleOrder::Add($arFields); $newOrderID = IntVal($newOrderID); if ($newOrderID <= 0) $bSuccess = False; } if ($bSuccess) { $arDiscounts = array(); $arDiscounts[$basketID] = $discountProduct; CSaleBasket::OrderBasket($newOrderID, $currentFUser, $arOrder["LID"], $arDiscounts); } if ($bSuccess) { for ($it = 0, $intCount = count($arTaxList); $it < $intCount; $it++) { $arFields = array( "ORDER_ID" => $newOrderID, "TAX_NAME" => $arTaxList[$it]["TAX_NAME"], "IS_PERCENT" => $arTaxList[$it]["IS_PERCENT"], "VALUE" => ($arTaxList[$it]["IS_PERCENT"]=="Y") ? $arTaxList[$it]["VALUE"] : RoundEx(CCurrencyRates::ConvertCurrency($arTaxList[$it]["VALUE"], $arTaxList[$it]["CURRENCY"], $baseSiteCurrency), 2), "VALUE_MONEY" => $arTaxList[$it]["VALUE_MONEY"], "APPLY_ORDER" => $arTaxList[$it]["APPLY_ORDER"], "IS_IN_PRICE" => $arTaxList[$it]["IS_IN_PRICE"], "CODE" => $arTaxList[$it]["CODE"] ); CSaleOrderTax::Add($arFields); } $dbOrderPropValues = CSaleOrderPropsValue::GetList( array(), array("ORDER_ID" => $arRecur["ORDER_ID"]), false, false, array("ORDER_PROPS_ID", "NAME", "CODE", "VALUE", "PROP_IS_PAYER", "PROP_IS_EMAIL") ); while ($arOrderPropValues = $dbOrderPropValues->Fetch()) { $arFields = array( "ORDER_ID" => $newOrderID, "ORDER_PROPS_ID" => $arOrderPropValues["ORDER_PROPS_ID"], "NAME" => $arOrderPropValues["NAME"], "CODE" => $arOrderPropValues["CODE"], "VALUE" => $arOrderPropValues["VALUE"] ); CSaleOrderPropsValue::Add($arFields); if ($arOrderPropValues["PROP_IS_PAYER"] == "Y") $payerName = $arOrderPropValues["VALUE"]; if ($arOrderPropValues["PROP_IS_EMAIL"] == "Y") $payerEMail = $arOrderPropValues["VALUE"]; } } if ($bSuccess) { if (CModule::IncludeModule("statistic")) CStatistic::Set_Event("eStore", "order_create", $newOrderID); } if ($bSuccess) { $strOrderList = ""; $dbBasketTmp = CSaleBasket::GetList( array("NAME" => "ASC"), array("ORDER_ID" => $newOrderID) ); while ($arBasketTmp = $dbBasketTmp->Fetch()) { $strOrderList .= $arBasketTmp["NAME"]." - ".$arBasketTmp["QUANTITY"]." ".GetMessage("SALE_QUANTITY_UNIT"); $strOrderList .= "\n"; } if (strlen($payerName) <= 0 || strlen($payerEMail) <= 0) { $dbUser = CUser::GetByID($arOrder["USER_ID"]); if ($arUser = $dbUser->Fetch()) { if (strlen($payerName) <= 0) $payerName = $arUser["NAME"].((strlen($arUser["NAME"])<=0 || strlen($arUser["LAST_NAME"])<=0) ? "" : " ").$arUser["LAST_NAME"]; if (strlen($payerEMail) <= 0) $payerEMail = $arUser["EMAIL"]; } } $arFields = Array( "ORDER_ID" => $newOrderID, "ORDER_DATE" => Date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT", $arOrder["LID"]))), "ORDER_USER" => $payerName, "PRICE" => SaleFormatCurrency($totalOrderPrice, $baseSiteCurrency), "BCC" => COption::GetOptionString("sale", "order_email", "order@".$SERVER_NAME), "EMAIL" => $payerEMail, "ORDER_LIST" => $strOrderList, "SALE_EMAIL" => COption::GetOptionString("sale", "order_email", "order@".$SERVER_NAME) ); $eventName = "SALE_NEW_ORDER_RECURRING"; $bSend = true; foreach(GetModuleEvents("sale", "OnOrderRecurringSendEmail", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, Array($newOrderID, &$eventName, &$arFields))===false) $bSend = false; } if($bSend) { $event = new CEvent; $event->Send($eventName, $arOrder["LID"], $arFields, "N"); } } if ($bSuccess) $DB->Commit(); else $DB->Rollback(); } } else { $totalOrderPrice = $arOrder["PRICE"]; $baseSiteCurrency = $arOrder["CURRENCY"]; } $res = False; if ($bSuccess) { $res = CSaleUserAccount::Pay($arOrder["USER_ID"], $totalOrderPrice, $baseSiteCurrency, $newOrderID, True); if ($res) { if ($arProduct["WITHOUT_ORDER"] == "N") { CSaleOrder::PayOrder($newOrderID, "Y", False, False, $arRecur["ID"]); CSaleOrder::DeliverOrder($newOrderID, "Y", $arRecur["ID"]); CSaleOrder::DeductOrder($newOrderID, "Y", "", true, array(), $arRecur["ID"]); } else { /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider($arProduct)) { $r = $productProvider::DeliverProduct(array( "PRODUCT_ID" => $arProduct["PRODUCT_ID"], "USER_ID" => $arOrder["USER_ID"], "PAID" => true )); } else { $r = CSaleBasket::ExecuteCallbackFunction( $arProduct["PAY_CALLBACK_FUNC"], $arRecur["MODULE"], $arProduct["PRODUCT_ID"], $arOrder["USER_ID"], true ); } } $arFields = array( "ORDER_ID" => $newOrderID, "PRODUCT_NAME" => $arProduct["PRODUCT_NAME"], "PRODUCT_URL" => $arProduct["PRODUCT_URL"], "PRICE_TYPE" => $arProduct["PRICE_TYPE"], "RECUR_SCHEME_TYPE" => $arProduct["RECUR_SCHEME_TYPE"], "RECUR_SCHEME_LENGTH" => $arProduct["RECUR_SCHEME_LENGTH"], "WITHOUT_ORDER" => $arProduct["WITHOUT_ORDER"], "PRIOR_DATE" => Date($GLOBALS["DB"]->DateFormatToPHP(CLang::GetDateFormat("FULL", SITE_ID))), "NEXT_DATE" => $arProduct["NEXT_DATE"], "REMAINING_ATTEMPTS" => (Defined("SALE_PROC_REC_ATTEMPTS") ? SALE_PROC_REC_ATTEMPTS : 3), "SUCCESS_PAYMENT" => "Y" ); CSaleRecurring::Update($arRecur["ID"], $arFields); } else { $arFields = array( "ORDER_ID" => $newOrderID, "PRODUCT_NAME" => $arProduct["PRODUCT_NAME"], "PRODUCT_URL" => $arProduct["PRODUCT_URL"], "PRICE_TYPE" => $arProduct["PRICE_TYPE"], "RECUR_SCHEME_LENGTH" => $arProduct["RECUR_SCHEME_LENGTH"], "RECUR_SCHEME_TYPE" => $arProduct["RECUR_SCHEME_TYPE"], "WITHOUT_ORDER" => $arProduct["WITHOUT_ORDER"], "NEXT_DATE" => Date($GLOBALS["DB"]->DateFormatToPHP(CLang::GetDateFormat("FULL", SITE_ID)), time() + SALE_PROC_REC_TIME + CTimeZone::GetOffset()), "REMAINING_ATTEMPTS" => (IntVal($arRecur["REMAINING_ATTEMPTS"]) - 1), "SUCCESS_PAYMENT" => "N" ); CSaleRecurring::Update($arRecur["ID"], $arFields); if ((IntVal($arRecur["REMAINING_ATTEMPTS"]) - 1) <= 0) { CSaleRecurring::CancelRecurring($arRecur["ID"], "Y", "Can't pay order"); /* $arFields["CANCELED"] = "Y"; $arFields["DATE_CANCELED"] = Date(CDatabase::DateFormatToPHP(CLang::GetDateFormat("FULL", LANG))); $arFields["CANCELED_REASON"] = "Can't pay order"; */ } } } return $res; }
/** * The function add viewed product * * @param array $arFields - params for add * @return true false */ public static function Add($arFields) { global $DB; global $USER; global $APPLICATION; foreach (GetModuleEvents("sale", "OnBeforeViewedAdd", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) { return false; } } if (isset($arFields["ID"])) { unset($arFields["ID"]); } $arFields["PRODUCT_ID"] = IntVal($arFields["PRODUCT_ID"]); $arFields["USER_ID"] = IntVal($arFields["USER_ID"]); $arFields["FUSER_ID"] = IntVal($arFields["FUSER_ID"]); $arFields["IBLOCK_ID"] = IntVal($arFields["IBLOCK_ID"]); if (strlen($arFields["CALLBACK_FUNC"]) <= 0) { $arFields["CALLBACK_FUNC"] = "CatalogViewedProductCallback"; } if (strlen($arFields["MODULE"]) <= 0) { $arFields["MODULE"] = "catalog"; } if (strlen($arFields["PRODUCT_PROVIDER_CLASS"]) <= 0 && $arFields["MODULE"] == "catalog") { $arFields["PRODUCT_PROVIDER_CLASS"] = "CCatalogProductProvider"; } if ($arFields["PRODUCT_ID"] <= 0) { return false; } if (strlen($arFields["LID"]) <= 0) { return false; } if (\Bitrix\Main\Loader::includeModule("catalog")) { if (\Bitrix\Main\Config\Option::get("sale", "viewed_capability", "") == "Y") { return \Bitrix\Catalog\CatalogViewedProductTable::refresh($arFields["PRODUCT_ID"], CSaleBasket::GetBasketUserID(), $arFields["LID"]); } } $arFilter = array(); $arFilter["PRODUCT_ID"] = $arFields["PRODUCT_ID"]; if ($arFields["USER_ID"] > 0) { $arFuserItems = CSaleUser::GetList(array("USER_ID" => $arFields["USER_ID"])); $FUSER_ID = $arFuserItems["ID"]; } elseif (IntVal($arFields["FUSER_ID"]) > 0) { $FUSER_ID = $arFields["FUSER_ID"]; } else { $FUSER_ID = CSaleBasket::GetBasketUserID(); } $arFilter["FUSER_ID"] = $FUSER_ID; $arFields["FUSER_ID"] = $FUSER_ID; $db_res = CSaleViewedProduct::GetList(array(), $arFilter, false, false, array('ID')); if (!($arItems = $db_res->Fetch())) { if (CModule::IncludeModule('catalog')) { /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider($arFields)) { $arResultTmp = $productProvider::ViewProduct(array("PRODUCT_ID" => $arFields["PRODUCT_ID"], "USER_ID" => $arFields["USER_ID"], "SITE_ID" => $arFields["LID"])); } else { $arResultTmp = CSaleBasket::ExecuteCallbackFunction($arFields["CALLBACK_FUNC"], $arFields["MODULE"], $arFields["PRODUCT_ID"], $arFields["USER_ID"], $arFields["LID"]); } if ($arResultTmp && count($arResultTmp) > 0) { $arFields = array_merge($arFields, $arResultTmp); } if (strlen($arFields["NAME"]) <= 0) { return false; } $arInsert = $DB->PrepareInsert("b_sale_viewed_product", $arFields); //chance deleted $rnd = mt_rand(0, 1000); if ($rnd < 100) { $db_res = CSaleViewedProduct::GetList(array(), array("FUSER_ID" => $FUSER_ID), array("COUNT" => "ID"), false); $arCount = $db_res->Fetch(); $viewedCount = COption::GetOptionString("sale", "viewed_count", "100"); if ($arCount["ID"] > IntVal($viewedCount)) { $limit = $arCount["ID"] - $viewedCount + $viewedCount * 0.2; CSaleViewedProduct::DeleteForUser($FUSER_ID, $limit); } } $strSql = "INSERT INTO b_sale_viewed_product (" . $arInsert[0] . ", DATE_VISIT) VALUES(" . $arInsert[1] . ", " . $DB->GetNowFunction() . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $ID = IntVal($DB->LastID()); } } else { $ID = IntVal($arItems["ID"]); $arFields["DATE_VISIT"] = $DB->GetNowFunction(); $arInsert = $DB->PrepareInsert("b_sale_viewed_product", $arFields); CSaleViewedProduct::Update($ID, $arFields); } foreach (GetModuleEvents("sale", "OnViewedAdd", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($arFields)); } return $ID; }
} } $lAdmin_tab4->AddGroupActionTable(array("order_basket" => GetMessage("BUYER_PD_ORDER"), "delay_y" => GetMessage("BUYER_PD_DELAY_Y"), "delay_n" => GetMessage("BUYER_PD_DELAY_N"), "delete_basket" => GetMessage("BUYER_PD_DELETE"))); if ($_REQUEST["table_id"] == $sTableID_tab4) { $lAdmin_tab4->CheckListMode(); } //END BUYERS BASKET //BUYERS VIEWED PRODUCT $sTableID_tab5 = "t_stat_list_tab5"; $oSort_tab5 = new CAdminSorting($sTableID_tab5); $lAdmin_tab5 = new CAdminList($sTableID_tab5, $oSort_tab5); //FILTER VIEWED $arFilterFields = array("filter_viewed_date_visit", "filter_date_visit_from", "filter_date_visit_to", "filter_viewed_lid"); $lAdmin_tab5->InitFilter($arFilterFields); $arFilter = array(); $arFuserItems = CSaleUser::GetList(array("USER_ID" => $ID)); $arFilter["FUSER_ID"] = $arFuserItems["ID"]; if (strlen($filter_viewed_lid) > 0) { $arFilter["LID"] = trim($filter_viewed_lid); } if (strlen(trim($filter_date_visit_from)) > 0) { $arFilter["DATE_FROM"] = FmtDate($filter_date_visit_from, "D.M.Y"); } if (strlen(trim($filter_date_visit_to)) > 0) { if ($arDate = ParseDateTime($filter_date_visit_to, CSite::GetDateFormat("FULL", SITE_ID))) { if (StrLen($filter_date_visit_to) < 11) { $arDate["HH"] = 23; $arDate["MI"] = 59; $arDate["SS"] = 59; } $filter_date_visit_to = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL", SITE_ID)), mktime($arDate["HH"], $arDate["MI"], $arDate["SS"], $arDate["MM"], $arDate["DD"], $arDate["YYYY"]));
public static function Add() { global $DB, $USER; $arFields = array("=DATE_INSERT" => $DB->GetNowFunction(), "=DATE_UPDATE" => $DB->GetNowFunction(), "USER_ID" => is_object($USER) && $USER->IsAuthorized() ? IntVal($USER->GetID()) : False, "CODE" => md5(time() . randString(10))); $ID = CSaleUser::_Add($arFields); $ID = IntVal($ID); $secure = false; if (COption::GetOptionString("sale", "use_secure_cookies", "N") == "Y" && CMain::IsHTTPS()) { $secure = 1; } if (COption::GetOptionString("sale", "encode_fuser_id", "N") == "Y") { $arRes = CSaleUser::GetList(array("ID" => $ID)); if (!empty($arRes)) { $GLOBALS["APPLICATION"]->set_cookie("SALE_UID", $arRes["CODE"], false, "/", false, $secure, "Y", false); } } else { $GLOBALS["APPLICATION"]->set_cookie("SALE_UID", $ID, false, "/", false, $secure, "Y", false); } return $ID; }
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; } }
<?php $_SERVER["DOCUMENT_ROOT"] = realpath(dirname(__FILE__) . "/.."); $DOCUMENT_ROOT = $_SERVER["DOCUMENT_ROOT"]; define("NO_KEEP_STATISTIC", true); define("NOT_CHECK_PERMISSIONS", true); define('CHK_EVENT', true); require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; @set_time_limit(0); @ignore_user_abort(true); CModule::IncludeModule('sale'); $arBasketItemsToUser = array(); $dbBasketItems = CSaleBasket::GetList(array(), array(">DATE_INSERT" => date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT")), mktime() - 60 * 60 * 24 * 30), ">USER_ID" => 0, "DELAY" => "Y")); //get list of positions inserted in 30 days while ($arItem = $dbBasketItems->Fetch()) { $arUser = CSaleUser::GetList(array('ID' => $arItem['FUSER_ID'])); $arItem["USER_ID"] = $arUser["USER_ID"]; $dbBasketItemsCheck = CSaleBasket::GetList(array(), array("PRODUCT_ID" => $arItem["PRODUCT_ID"], "USER_ID" => $arItem["USER_ID"], ">ORDER_ID" => 0)); if (!$dbBasketItemsCheck->Fetch()) { $arBasketItemsToUser[$arItem["USER_ID"]][] = $arItem; //filling array with list of positions to user } } $ORDERLIST = ''; $arEventFields = array(); //Parameters for post template foreach ($arBasketItemsToUser as $USER_ID => $basketItems) { $rsUser = CUser::GetByID($USER_ID); if ($arUser = $rsUser->Fetch()) { foreach ($basketItems as $basketItem) { $ORDERLIST .= $basketItem["NAME"] . ' - ' . $basketItem["PRICE"] . " " . $basketItem["CURRENCY"] . "<br />";