Добавление нового заказа API-методами Битрикс

UPD: в скрипте используются старые методы работы с заказом, для тех у кого Битрикс новых редакций рекомендую в работе с заказами использовать D7!

Пост не удаляю, чтобы вновь открыв его, ужаснуться какие раньше велосипеды изобретал :)

Данной темы косвенно касался уже несколько раз, напишу более простой и обновленный вариант оформления заказа с помощью API методов Битрикса. Если кому-то понадобится буду рад=)


require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");
$APPLICATION->SetTitle("Перенос заказов");
@set_time_limit(0);

if(!CModule::IncludeModule("sale") && !CModule::IncludeModule("catalog"))
	die();

if(
	!empty($_POST["FIO"])&&
	!empty($_POST["EMAIL"])&&
	!empty($_POST["PHONE"])
)
{

	// Шаг 0. Lexa.pro: параметры
	
	$arIBLOCKS = array(10, 11); // инфоблоки с товарами
	// в моем случае одинаковое для двух инфоблоков
	$typePrice = 1; // Тип цены
	
	$PERSON_TYPE_ID = 1;
	$PAY_SYSTEM_ID = 1;
	$DELIVERY_ID = 2;

	// Шаг 1. Lexa.pro: найти/создать пользователя
	
	global $USER;

	$emailUser = CUser::GetList($by="", $order="", array('=EMAIL' => $_POST["EMAIL"]));
	while($arUser = $emailUser->Fetch())
		$USER_ID = $arUser["ID"];
			
	if(empty($USER_ID)){ // Если не нашлось email-а в БД, созданим нового юзвера
		
		$NEW_LOGIN = $_POST["EMAIL"];
		$NEW_EMAIL = $_POST["EMAIL"];
		$NEW_NAME = "";
		$NEW_LAST_NAME = "";

		if(strlen($_POST["FIO"]) > 0)
		{
			$arNames = explode(" ", $_POST["FIO"]);
			$NEW_NAME = $arNames[1];
			$NEW_LAST_NAME = $arNames[0];
		}

		$pos = strpos($NEW_LOGIN, "@");
		if ($pos !== false)
			$NEW_LOGIN = substr($NEW_LOGIN, 0, $pos);

		if (strlen($NEW_LOGIN) > 47)
			$NEW_LOGIN = substr($NEW_LOGIN, 0, 47);

		if (strlen($NEW_LOGIN) < 3)
			$NEW_LOGIN .= "___";

		$dbUserLogin = CUser::GetByLogin($NEW_LOGIN);
		if ($arUserLogin = $dbUserLogin->Fetch())
		{
			$newLoginTmp = $NEW_LOGIN;
			$uind = 0;
			do
			{
				$uind++;
				if ($uind == 10)
				{
					$NEW_LOGIN = $arUserResult["USER_EMAIL"];
					$newLoginTmp = $NEW_LOGIN;
				}
				elseif ($uind > 10)
				{
					$NEW_LOGIN = "buyer".time().GetRandomCode(2);
					$newLoginTmp = $NEW_LOGIN;
					break;
				}
				else
				{
					$newLoginTmp = $NEW_LOGIN.$uind;
				}
				$dbUserLogin = CUser::GetByLogin($newLoginTmp);
			}
			while ($arUserLogin = $dbUserLogin->Fetch());
			$NEW_LOGIN = $newLoginTmp;
		}

		$GROUP_ID = array(2);
		$def_group = COption::GetOptionString("main", "new_user_registration_def_group", "");
		if($def_group!="")
		{
			$GROUP_ID = explode(",", $def_group);
			$arPolicy = $USER->GetGroupPolicy($GROUP_ID);
		}
		else
		{
			$arPolicy = $USER->GetGroupPolicy(array());
		}

		$password_min_length = intval($arPolicy["PASSWORD_LENGTH"]);
		if($password_min_length <= 0)
			$password_min_length = 6;
		$password_chars = array(
			"abcdefghijklnmopqrstuvwxyz",
			"ABCDEFGHIJKLNMOPQRSTUVWXYZ",
			"0123456789",
		);
		if($arPolicy["PASSWORD_PUNCTUATION"] === "Y")
			$password_chars[] = ",.<>/?;:'\"[]{}\|`~!@#\$%^&*()-_+=";
		$NEW_PASSWORD = $NEW_PASSWORD_CONFIRM = randString($password_min_length+2, $password_chars);

		$user = new CUser;
		$arAuthResult = $user->Add(Array(
			"LOGIN" => $NEW_LOGIN,
			"NAME" => $NEW_NAME,
			"LAST_NAME" => $NEW_LAST_NAME,
			"PASSWORD" => $NEW_PASSWORD,
			"CONFIRM_PASSWORD" => $NEW_PASSWORD_CONFIRM,
			"EMAIL" => $NEW_EMAIL,
			"GROUP_ID" => $GROUP_ID,
			"ACTIVE" => "Y",
			"LID" => SITE_ID,
			)
		);

		if (IntVal($arAuthResult) <= 0)
		{
			$arResult["ERROR"][] = GetMessage("STOF_ERROR_REG").((strlen($user->LAST_ERROR) > 0) ? ": ".$user->LAST_ERROR : "" );
		}
		else
		{
			$USER->Authorize($arAuthResult);
		}
	} else {
		$USER->Authorize($USER_ID); // авторизуем, если новый
	}
	
	// Шаг 2. Lexa.pro: оформляем заказ
	// в моем случае не важно какие тип платильщика, способы доставки и оплаты были указаны

	// 2.1 Получаем корзину
	$basket = array(); // корзина
	$summ = 0;
	
	$dbBasketItems = CSaleBasket::GetList(
		 array(),
		 array("FUSER_ID" => CSaleBasket::GetBasketUserID(),"LID" => SITE_ID, "ORDER_ID" => "NULL"),
		 false,
		 false,
		 array("ID", "CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "QUANTITY", "PRODUCT_PROVIDER_CLASS", "PRICE")
	);
	while ($arItems = $dbBasketItems->GetNext())
	{
		$basket[] = $arItems;
		$summ += $basket["QUANTITY"]*$basket["PRICE"];
	}

	// 2.2Добавляем заказ
	$arOrderDat = CSaleOrder::DoCalculateOrder(
		SITE_ID,
		$USER->GetID(),
		$basket,
		$PERSON_TYPE_ID, // тип плательщика
		array(),
		$DELIVERY_ID, // доставка
		$PAY_SYSTEM_ID, // оплата
		array(),
		$arErrors,
		$arWarnings
	);	
	
	
	$arFields = array(
		"LID" => SITE_ID,
		"PERSON_TYPE_ID" => $PERSON_TYPE_ID,
		"PAYED" => "N",
		"CANCELED" => "N",
		"STATUS_ID" => "N",
		"PRICE" => $summ,
		"CURRENCY" => "RUB",
		"USER_ID" => (int)$USER->GetID(),
		"PAY_SYSTEM_ID" => $PAY_SYSTEM_ID,
		//"PRICE_DELIVERY" => $arResult["DELIVERY_PRICE"],
		"DELIVERY_ID" => $DELIVERY_ID,
		//"DISCOUNT_VALUE" => $arResult["DISCOUNT_PRICE"],
		//"TAX_VALUE" => $arResult["bUsingVat"] == "Y" ? $arResult["VAT_SUM"] : $arResult["TAX_PRICE"],
		"USER_DESCRIPTION" => $_POST["SITE"],
		"ORDER_PROP" => array(
			3 => $_POST["PHONE"],
			1 => $_POST["FIO"],
			7 => $_POST["ADDRESS"],
			2=> $_POST["EMAIL"],
		),
	);
	
	//не получилось прикрепить корзину к заказу
	$orderID = (int)CSaleOrder::DoSaveOrder($arOrderDat, $arFields, 0, $arErrors);
	CSaleBasket::OrderBasket($orderID, $_SESSION["SALE_USER_ID"], SITE_ID); // привязывает товары из корзины к заказу.

}

Возврат к списку


0
Anthony
[URL=https://www.christianslouboutin.us.com/]Christian Louboutin Outlet[/URL]
[URL=https://www.air-max95.us.com/]Air Max 95[/URL]
[URL=https://www.airforce-1.us.org/]Air Force 1 Mid[/URL]
[URL=https://www.christianlouboutins.uk.com/]Christian Louboutin[/URL]
[URL=https://www.nikefactory-outlet.us.org/]Nike Factory[/URL]
[URL=https://www.pandora-us.us/]Pandora Jewelry[/URL]
[URL=https://www.max97trainers.uk.com/]Nike Air Max[/URL]
[URL=https://www.cheapnikesshoes.us.com/]Cheap Nike Shoes[/URL]
[URL=https://www.ferragamobelts.us.com/]Ferragamo Belt[/URL]
[URL=https://www.pandoracanadajewelrycharms.ca/]Pandora Charms[/URL]
[URL=https://www.christian-louboutin-shoes.us.org/]Christian Louboutin Heels[/URL]
[URL=https://www.pandorabraceletsforwomen.us/]Pandora Bracelet[/URL]
[URL=https://www.sneakerswebsite.us/]Nike Sneakers[/URL]
[URL=https://www.christian-louboutins.us.org/]Christian Louboutin[/URL]
[URL=https://www.nike-stores.us.org/]Nike Outlet Store[/URL]
[URL=https://www.fjallravenbackpack.us/]Fjallraven Kanken Backpack[/URL]
[URL=https://www.nike-outletstores.us.com/]Nike Outlet Online[/URL]
[URL=https://www.yeezysboosts.us.com/]Yeezy Boost 750[/URL]
[URL=https://www.christianlouboutins-outlet.us.com/]Louboutin Shoes[/URL]
[URL=https://www.nikesclearance.us/]Nike Clearance Outlet[/URL]
[URL=https://www.ferragamosshoes.us.com/]Ferragamo[/URL]
[URL=https://www.vansshoes-outlets.us.com/]Vans[/URL]
[URL=https://www.nike-clearance.us.com/]Nike Clearance[/URL]
[URL=https://www.yeezyshoess.us.com/]Adidas Yeezy[/URL]
[URL=https://www.nike-zoom.us.com/]Nike Zoom[/URL]
[URL=https://www.airforceones.us.com/]Air Force Ones[/URL]
[URL=https://www.outletstoreonlineshopping.us/]Nike Outlet Store Online Shopping[/URL]
[URL=https://www.nikesneakersoutlet.us.org/]Nike Sneakers[/URL]
[URL=https://www.nikeoutlet-factory.us.com/]Nike Factory[/URL]
[URL=https://www.yeezysneakersboost.us/]Yeezy Sneakers[/URL]
[URL=https://www.ultra-boosts.us.com/]Ultra Boost[/URL]
[URL=https://www.nikefactorystoreonline.us.com/]Nike Factory Store Online[/URL]
[URL=https://www.pandorabracelets-clearance.us.com/]Pandora Bracelets[/URL]
[URL=https://www.nikecortezshox.us.com/]Nike Cortez[/URL]
[URL=https://www.air-jordansretro.us.com/]Jordans Retro[/URL]
[URL=https://www.yeezyscheap.us.com/]Yeezys[/URL]
[URL=https://www.pandorashop.ca/]Pandora[/URL]
[URL=https://www.lebron-jamesshoes.us.org/]Lebron James Sneakers[/URL]
[URL=https://www.nikeoutletstores.us.org/]Nike Outlet Online[/URL]
[URL=https://www.nikefreerun.us.org/]Nike Free Run[/URL]
[URL=https://www.nikeoutletstoreonline-shopping.us.com/]Nike Outlet Store Online Shopping[/URL]
[URL=https://www.charmsbracelet.uk.com/]Pandora Bracelet[/URL]
[URL=https://www.kyrieirvingbasketballshoes.us.com/]Nike Kyrie[/URL]
[URL=https://www.yeezyboosts-350.us.com/]Yeezy Boost 350[/URL]
[URL=https://www.nikestorefactory.us.com/]Nike Outlet Store[/URL]
[URL=https://www.menwomenshoes.us/]Nike Shoes[/URL]
[URL=https://www.redbottomshoes-forwomen.us/]Red Bottom Shoes[/URL]
[URL=https://www.yeezys-adidas.us.com/]Adidas Yeezy[/URL]
[URL=https://www.redbottomslouboutinshoes.us/]Louboutin Shoes[/URL]
[URL=https://www.michael-jordanshoes.us.com/]Michael Jordan Shoes[/URL]
[URL=https://www.jewelrycharmsrings.uk.com/]Pandora Sale[/URL]
[URL=https://www.nikeoutletstore-onlineshopping.us.org/]Nike Outlet Store Online Shopping[/URL]
[URL=https://www.louboutinshoess.us/]Louboutin[/URL]
[URL=https://www.ferragamo-shoes.us.org/]Ferragamo Shoes[/URL]
[URL=https://www.nikecortez.us.org/]Nike Cortez[/URL]
[URL=https://www.red-bottomshoesforwomen.us.com/]Red Bottom Shoes[/URL]
[URL=https://www.moncleroutletuk.uk.com/]Moncler UK[/URL]
[URL=https://www.kevin-durantsshoes.us.com/]Nike KD[/URL]
[URL=https://www.christianlouboutinshoessaleoutlet.us/]Christian Louboutin Shoes[/URL]
[URL=https://www.adidasstan-smith.us.com/]Adidas Stan Smith[/URL]
[URL=https://www.pandorasjewelryoutlet.us.com/]Pandora Jewelry[/URL]
[URL=https://www.nikeshoesclearance.us.com/]Nike Clearance[/URL]
[URL=https://www.airjordanssneakers.us.org/]Jordans Sneakers[/URL]
[URL=https://www.nikeairmax720.us.org/]Nike Air Max 720 Men[/URL]
[URL=https://www.nikeoutletstoreonlines.us.com/]Nike Outlet Store[/URL]
[URL=https://www.nikeshoesonlines.us.com/]Nike Shoes[/URL]
[URL=https://www.shoesyeezy.us.com/]Yeezy Shoes[/URL]
[URL=https://www.nikefactorys.us/]Nike Factory[/URL]
[URL=https://www.nike-runningshoes.us/]Nike Running Shoes For Women[/URL]
[URL=https://www.nikeoutletonlineclearance.us.com/]Nike Clearance Outlet[/URL]
[URL=https://www.lebron16shoes.us.org/]Lebron 16[/URL]
[URL=https://www.christianlouboutins.us.org/]Christian Louboutin[/URL]
[URL=https://www.pandoracom.ca/]Pandora Canada[/URL]
[URL=https://www.christian-louboutinoutletsale.us.com/]Christian Louboutin Shoes[/URL]
[URL=https://www.lebronjamesshoessale.us.com/]Lebron Shoes[/URL]
[URL=https://www.nikefreernrun.us.com/]Nike Free Run[/URL]
[URL=https://www.nikeair-max270.us/]Nike Air Max 270 Men[/URL]
[URL=https://www.pandorajewelryofficialwebsite.us/]Pandora Jewelry Official Site USA[/URL]
[URL=https://www.nikestores.us.org/]Nike Outlet Store[/URL]
[URL=https://www.nikeshoesfactorys.us.com/]Nike Air Mag[/URL]
[URL=https://www.airjordanshoesretros.us.com/]Jordan Shoes[/URL]
[URL=https://www.nike-presto.us.com/]Nike Presto[/URL]
[URL=https://www.lebron17.us.org/]Lebron 17[/URL]
[URL=https://www.nikeshoes2019.us.com/]Nike Shoes[/URL]
[URL=https://www.nikeshoess.us.org/]Kids Nike Shoes[/URL]
[URL=https://www.nikeoutletstoreclearance.us.com/]Nike Clearance[/URL]
[URL=https://www.valentinoshoessale.us.com/]Valentino[/URL]
[URL=https://www.nikes-sneakers.us.com/]Nike Sneakers[/URL]
[URL=https://www.nikeshoescybermondayblackfriday.us.com/]Nike Shoes Cyber Monday[/URL]
[URL=https://www.nikerunning-shoes.us.com/]Nike Running Shoes For Women[/URL]
[URL=https://www.louboutinheelsshoes.us.com/]Louboutin Shoes[/URL]
[URL=https://www.golden-gooses.us.com/]Golden Goose Shoes[/URL]
[URL=https://www.nikeoutletonline-store.us.com/]Nike Outlet Store[/URL]
[URL=https://www.nike--shoes.us.com/]Nike Shoes[/URL]
[URL=https://www.christianlouboutinshoessaleoutlets.us/]Christian Louboutin Outlet[/URL]
[URL=https://www.pandoranecklaces.us/]Pandora Necklace Women[/URL]
[URL=https://www.nike-airmax98.us/]Nike Air Max 98[/URL]
[URL=https://www.yeezy500.us.org/]Yeezy 500[/URL]
[URL=https://www.newnikeshoes.us.org/]New Nike[/URL]
[URL=https://www.nikeairforce.us.org/]Nike Air Force[/URL]
[URL=https://www.jordan11gammablue.us/]Jordan 11 Blue[/URL]
[URL=https://www.nikeairmax720.us.com/]Air Max 720[/URL]
[URL=https://www.jewelrycharms.us/]Pandora Charms[/URL]
[URL=https://www.runningshoesformenwomen.us/]Nike Running Shoes For Women[/URL]
[URL=https://www.pandora-earrings.us/]Pandora Earrings[/URL]
[URL=https://www.nikebasketball-shoes.us.com/]Nike Basketball Shoes[/URL]
[URL=https://www.nike-outletstoreonlineshopping.us.com/]Nike Outlet Store Online Shopping[/URL]
[URL=https://www.new-nikeshoes.us.com/]New Nike Shoes[/URL]
[URL=https://www.adidassneakers.us.com/]Adidas Sneakers For Men[/URL]
[URL=https://www.lebron16shoes.us/]Lebron 16 Shoes[/URL]
[URL=https://www.newshoes2019.us/]Nike Shoes[/URL]
[URL=https://www.adidas-yeezysshoes.us.com/]Adidas Yeezy[/URL]
[URL=https://www.fjallravenkankenbackpack.us/]Fjallraven Kanken[/URL]
[URL=https://www.asicsshoesoutlet.us.com/]Asics Outlet[/URL]
[URL=https://www.charmsjewelryrings.uk.com/]Pandora Rings[/URL]
[URL=https://www.jordanretroshoes.us.org/]Jordan Retro[/URL]
[URL=https://www.airjordans-sneakers.us/]Jordans Sneakers[/URL]
[URL=https://www.nikehuaraches.us.com/]Nike Huarache[/URL]
[URL=https://www.nike-basketballshoes.us.org/]Nike Basketball Shoes[/URL]
[URL=https://www.nmdr1adidas.us.com/]Adidas NMD R1[/URL]
[URL=https://www.airforce1shoes.us.com/]Nike Air Force 1 Women[/URL]
[URL=https://www.nikeairzooms.us.com/]Nike Air Zoom[/URL]
[URL=https://www.red-bottomheels.us/]Red Bottom Heels[/URL]
[URL=https://www.airjordan-retro11.us.com/]Air Jordan 11[/URL]
[URL=https://www.christian-louboutins-shoes.us.com/]Christian Louboutin Heels[/URL]
[URL=https://www.airmax-98.us.com/]Air Max 98[/URL]
[URL=https://www.nikeshoesfactorystore.us.com/]Nike Shoes[/URL]
[URL=https://www.jordans13retro.us/]Jordan 13 Retro[/URL]
[URL=https://www.nikecom.us.com/]Nike[/URL]
[URL=https://www.jewelrynecklacerings.uk.com/]Pandora UK[/URL]
[URL=https://www.adidasultra-boosts.us.com/]Adidas Ultra Boost[/URL]
[URL=https://www.nikesneakerssale.us.com/]Nike Sneakers For Men[/URL]
[URL=https://www.pandora-jewelryrings.us/]Pandora Ring[/URL]
[URL=https://www.kyrie-irvingshoes.us.org/]Kyrie Irving Shoes[/URL]
[URL=https://www.jordanshoesforkids.us/]Kids Jordan Shoes[/URL]
[URL=https://www.nikeshoesshop.us.com/]Womens Nike Shoes[/URL]
[URL=https://www.adidas-nmds.us.org/]NMD Adidas[/URL]
[URL=https://www.nikeair-max.us.org/]Nike Air Max[/URL]
[URL=https://www.shoes-yeezy.us.com/]Yeezy[/URL]
[URL=https://www.nikereactuptempo.us.com/]Nike React[/URL]
[URL=https://www.pandoracharmscom.us/]Pandora Bracelet Charms[/URL]
[URL=https://www.airmax2019.us.org/]Air Max 2019[/URL]
Имя Цитировать 0
0
Гость

off white af1 [URL=https://www.offwhitesaler.com/]https://www.offwhitesaler.com/[/URL] ,

Golden Goose Sneakers [URL=https://www.goldengooseltd.com/]https://www.goldengooseltd.com/[/URL] ,

supreme clothing [URL=https://www.supremevipshop.com/]https://www.supremevipshop.com/[/URL] ,

Off White T Shirt [URL=https://www.offwhiteclothes.com/]https://www.offwhiteclothes.com/[/URL] ,

Golden Goose Sneakers Sale [URL=https://www.goldengoosesneakersltd.com/]https://www.goldengoosesneakersltd.com/[/URL] ,

stone island clothing [URL=https://www.stoneislandsaler.com/]https://www.stoneislandsaler.com/[/URL] ,

palm angels outlet [URL=https://www.palmangelsoutlet.com/]https://www.palmangelsoutlet.com/[/URL] ,

Golden Goose Sale [URL=https://www.goldengoosesos.com/]https://www.goldengoosesos.com/[/URL] ,

palm angels [URL=https://www.palmangelssale.com/]https://www.palmangelssale.com/[/URL] ,

Golden Goose Outlet [URL=https://www.goldengoosers.com/]https://www.goldengoosers.com/[/URL] ,

Имя Цитировать 0
Текст сообщения*
Защита от автоматических сообщений