本文整理汇总了PHP中Bitrix\Sale\Order::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::create方法的具体用法?PHP Order::create怎么用?PHP Order::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitrix\Sale\Order
的用法示例。
在下文中一共展示了Order::create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processOrder
public function processOrder($orderEbay)
{
Ebay::log(Logger::LOG_LEVEL_DEBUG, "EBAY_DATA_PROCESSOR_ORDER_PROCESSING", $orderEbay["ExtendedOrderID"], print_r($orderEbay, true), $this->siteId);
/*
* only in this case order is completely ready for shipping
*/
if ($orderEbay["OrderStatus"] != "Completed" || !isset($orderEbay["CheckoutStatus"]["eBayPaymentStatus"]) || $orderEbay["CheckoutStatus"]["eBayPaymentStatus"] != "NoPaymentFailure") {
Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_SKIPPED", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_SKIPPED", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId);
return array();
}
$ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance();
$settings = $ebay->getSettings();
if (!isset($settings[$this->siteId]["ORDER_PROPS"]) || !is_array($settings[$this->siteId]["ORDER_PROPS"])) {
throw new SystemException("Can't get order props map");
}
$propsMap = $settings[$this->siteId]["ORDER_PROPS"];
/*
if(strtolower(SITE_CHARSET) != 'utf-8')
$orderEbay = \Bitrix\Main\Text\Encoding::convertEncodingArray($orderEbay, 'UTF-8', SITE_CHARSET);
*/
$dbRes = OrderTable::getList(array("filter" => array("TRADING_PLATFORM_ID" => $ebay->getId(), "EXTERNAL_ORDER_ID" => $orderEbay["ExtendedOrderID"])));
if ($orderCorrespondence = $dbRes->fetch()) {
Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_ALREADY_EXIST", $orderEbay["ExtendedOrderID"], Loc::getMessage("SALE_TP_EBAY_FDPO_ORDER_SKIPPED_EXIST", array("#ORDER_ID#" => $orderEbay["ExtendedOrderID"])), $this->siteId);
return array();
}
/** @var \Bitrix\Sale\Order $order */
$order = \Bitrix\Sale\Order::create($this->siteId);
$order->setPersonTypeId($settings[$this->siteId]["PERSON_TYPE"]);
$propsCollection = $order->getPropertyCollection();
/** @var \Bitrix\Sale\PropertyValueCollection $propCollection */
if (intval($propsMap["FIO"]) > 0) {
$prop = $propsCollection->getItemByOrderPropertyId($propsMap["FIO"]);
$prop->setValue($orderEbay["ShippingAddress"]["Name"]);
}
if (intval($propsMap["CITY"]) > 0) {
$prop = $propsCollection->getItemByOrderPropertyId($propsMap["CITY"]);
$prop->setValue($orderEbay["ShippingAddress"]["CityName"]);
}
if (intval($propsMap["PHONE"]) > 0) {
$prop = $propsCollection->getItemByOrderPropertyId($propsMap["PHONE"]);
$prop->setValue($orderEbay["ShippingAddress"]["Phone"]);
}
if (intval($propsMap["ZIP"]) > 0) {
$prop = $propsCollection->getItemByOrderPropertyId($propsMap["ZIP"]);
$prop->setValue($orderEbay["ShippingAddress"]["PostalCode"]);
}
if (intval($propsMap["ADDRESS"]) > 0) {
$prop = $propsCollection->getItemByOrderPropertyId($propsMap["ADDRESS"]);
$prop->setValue($orderEbay["ShippingAddress"]["CountryName"] . " " . $orderEbay["ShippingAddress"]["CityName"] . " " . $orderEbay["ShippingAddress"]["Street1"] . " " . (!empty($orderEbay["ShippingAddress"]["Street2"]) ? $orderEbay["ShippingAddress"]["Street2"] . " " : ""));
}
$basket = null;
$bitrixOrderId = 0;
$userId = 0;
$orderLineItemsIds = array();
$transactionsArray = $this->normalizeTransactionsArray($orderEbay["TransactionArray"]);
foreach ($transactionsArray as $transaction) {
//if we have more than one transaction let's create user from the first
if ($userId <= 0) {
if (intval($propsMap["EMAIL"]) > 0 && !empty($transaction["Buyer"]["Email"])) {
$prop = $propsCollection->getItemByOrderPropertyId($propsMap["EMAIL"]);
$prop->setValue($transaction["Buyer"]["Email"]);
$userId = $this->createUser($transaction["Buyer"]["Email"], array("NAME" => $transaction["Buyer"]["UserFirstName"], "LAST_NAME" => $transaction["Buyer"]["UserLastName"]));
}
if ($userId <= 0) {
$userId = \CSaleUser::GetAnonymousUserID();
}
}
if (intval($userId > 0)) {
$order->setFieldNoDemand("USER_ID", $userId);
}
$fUserId = null;
if ($order->getUserId() > 0) {
$fUserId = Fuser::getIdByUserId($order->getUserId());
}
/** @var \Bitrix\Sale\Basket $basket */
if (!$basket) {
$basket = \Bitrix\Sale\Basket::create($this->siteId);
$basket->setFUserId($fUserId);
}
$items = array();
$isVariation = false;
if (!empty($transaction["Item"])) {
$items = Xml2Array::normalize($transaction["Item"]);
} elseif (!empty($transaction["Variation"])) {
$items = Xml2Array::normalize($transaction["Variation"]);
$isVariation = true;
}
if (empty($items)) {
Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_PROCESSING_TRANSACTION_ITEM_NOT_FOUND", $transaction["OrderLineItemID"], print_r($transaction, true), $this->siteId);
continue;
}
foreach ($items as $transactionItem) {
$ebaySku = $isVariation ? $this->getSkuVariation($transactionItem["SKU"]) : $this->getSku($transactionItem["SKU"]);
if (strlen($ebaySku) <= 0) {
Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_ORDER_PROCESSING_TRANSACTION_ITEM_SKU_NOT_FOUND", $transaction["OrderLineItemID"], print_r($transaction, true), $this->siteId);
continue;
}
$item = $basket->createItem('catalog', $ebaySku);
$item->setField("PRODUCT_PROVIDER_CLASS", "CCatalogProductProvider");
$itemData = array("CUSTOM_PRICE" => "Y", "PRICE" => floatval($transaction["TransactionPrice"]), "QUANTITY" => floatval($transaction["QuantityPurchased"]), "NAME" => !empty($transactionItem["VariationTitle"]) ? $transactionItem["VariationTitle"] : $transactionItem["Title"], "CURRENCY" => SiteCurrencyTable::getSiteCurrency($this->siteId));
//.........这里部分代码省略.........
示例2: create
/**
* @param array $fields
* @return Sale\Order
* @throws Main\ObjectNotFoundException
* @throws Sale\UserMessageException
* @throws \Bitrix\Main\ArgumentNullException
* @throws \Bitrix\Main\ArgumentOutOfRangeException
* @throws \Bitrix\Main\NotSupportedException
* @throws \Bitrix\Main\SystemException
*/
public static function create(array $fields)
{
$adminSection = defined('ADMIN_SECTION') && ADMIN_SECTION === true;
$orderCompatibility = new static();
$lid = $fields['LID'];
$userId = $fields['USER_ID'];
$currency = $fields['CURRENCY'];
if (isset($fields['ID']) && intval($fields['ID']) > 0) {
/** @var Sale\Order $order */
if (!($order = Sale\Order::load($fields['ID']))) {
throw new Sale\UserMessageException('Order not found');
}
} else {
/** @var Sale\Order $order */
if (!($order = Sale\Order::create($lid, $userId, $currency))) {
throw new Sale\UserMessageException('Order not create');
}
}
if (isset($fields['PERSON_TYPE_ID']) && intval($fields['PERSON_TYPE_ID']) > 0) {
$order->setPersonTypeId($fields['PERSON_TYPE_ID']);
}
if (!empty($fields['ORDER_PROP']) && is_array($fields['ORDER_PROP'])) {
$fields['PROPERTIES'] = $fields['ORDER_PROP'];
}
$propCollection = $order->getPropertyCollection();
/** @var Sale\Result $r */
$propCollection->setValuesFromPost($fields, $_FILES);
if (!isset($fields['DATE_STATUS'])) {
$fields['DATE_STATUS'] = new Main\Type\DateTime();
}
$orderFields = static::replaceFields($fields, static::getOrderReplaceFields());
$orderFields = $orderCompatibility->parseRawFields(static::ENTITY_ORDER, $orderFields);
$orderFields = static::clearFields($orderFields);
foreach (static::getFieldsFromOtherEntities() as $wrongField) {
if (array_key_exists($wrongField, $fields)) {
unset($orderFields[$wrongField]);
}
}
$orderFields = static::convertDateFields($orderFields, static::getOrderDateFields());
unset($orderFields['MARKED']);
unset($orderFields['CANCELED']);
if (array_key_exists('PRICE', $orderFields)) {
$orderCompatibility->externalPrice = $orderFields['PRICE'];
}
if ($order->getId() > 0) {
if ($adminSection) {
unset($orderFields['PRICE']);
}
unset($orderFields['PRICE_DELIVERY']);
unset($orderFields['DISCOUNT_VALUE']);
unset($orderFields['TAX_VALUE']);
$order->setField('DATE_UPDATE', new Main\Type\DateTime());
} else {
if (!$adminSection) {
unset($orderFields['SUM_PAID']);
}
$order->setField('DATE_INSERT', new Main\Type\DateTime());
$order->setField('DATE_UPDATE', new Main\Type\DateTime());
}
unset($orderFields['TAX_PRICE']);
$order->setFieldsNoDemand($orderFields);
$orderCompatibility->order = $order;
$orderCompatibility->requestFields = $fields;
$order->getDiscount();
return $orderCompatibility;
}
示例3: convertOrderOldToNew
/**
* @param array $oldOrder
* @return Shipment
* @internal
*/
public static function convertOrderOldToNew(array $oldOrder)
{
$siteId = isset($oldOrder["SITE_ID"]) ? $oldOrder["SITE_ID"] : SITE_ID;
$newOrder = \Bitrix\Sale\Order::create($siteId, null, $oldOrder["CURRENCY"]);
$dbPersonType = \CSalePersonType::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("ACTIVE" => "Y", "LID" => $siteId));
if ($arPersonType = $dbPersonType->GetNext()) {
$personTypeId = $arPersonType["ID"];
} else {
$personTypeId = 1;
}
$newOrder->setPersonTypeId($personTypeId);
$newOrder->setFieldNoDemand("PRICE", $oldOrder["PRICE"]);
$basket = \Bitrix\Sale\Basket::create($siteId);
$settableFields = array_flip(\Bitrix\Sale\BasketItemBase::getSettableFields());
if (!empty($oldOrder["ITEMS"]) && is_array($oldOrder["ITEMS"])) {
foreach ($oldOrder["ITEMS"] as $oldBasketItem) {
$newBasketItem = $basket->createItem($oldBasketItem["MODULE"], $oldBasketItem["PRODUCT_ID"]);
$oldBasketItem = array_intersect_key($oldBasketItem, $settableFields);
$newBasketItem->setFieldsNoDemand($oldBasketItem);
}
}
$props = $newOrder->getPropertyCollection();
if (!empty($oldOrder['PROPERTIES']) && is_array($oldOrder['PROPERTIES'])) {
$r = $props->setValuesFromPost($oldOrder, $_FILES);
}
$newOrder->setBasket($basket);
if ($loc = $props->getDeliveryLocation()) {
$loc->setValue($oldOrder["LOCATION_TO"]);
}
if ($loc = $props->getDeliveryLocationZip()) {
$loc->setValue($oldOrder["LOCATION_ZIP"]);
}
/** @var \Bitrix\Sale\ShipmentCollection $shipmentCollection */
$shipmentCollection = $newOrder->getShipmentCollection();
$shipment = $shipmentCollection->createItem();
$shipment->setField("CURRENCY", $oldOrder["CURRENCY"]);
$shipmentItemCollection = $shipment->getShipmentItemCollection();
foreach ($newOrder->getBasket() as $item) {
$shipmentItem = $shipmentItemCollection->createItem($item);
$shipmentItem->setQuantity($item->getQuantity());
if (strlen($shipmentItem->getField("DIMENSIONS"))) {
$shipmentItem->setField("DIMENSIONS", unserialize($shipmentItem->getField("DIMENSIONS")));
}
}
if (isset($arOrder["DELIVERY_EXTRA_SERVICES"])) {
$shipment->setExtraServices($arOrder["DELIVERY_EXTRA_SERVICES"]);
}
return $shipment;
}
示例4: array
$originalDeliveryId = $shipment->getDeliveryId();
$customPriceDelivery = $shipment->getField('CUSTOM_PRICE_DELIVERY');
$basePrice = $shipment->getField('BASE_PRICE_DELIVERY');
break;
}
}
if ($originalDeliveryId > 0) {
$shipment = $order->getShipmentCollection()->createItem();
$shipment->setField('DELIVERY_ID', $originalDeliveryId);
$shipment->setField('CUSTOM_PRICE_DELIVERY', $customPriceDelivery);
$shipment->setField('BASE_PRICE_DELIVERY', $basePrice);
}
$order->getDiscount()->calculate();
}
} else {
$order = \Bitrix\Sale\Order::create($siteId);
$order->setPersonTypeId(Blocks\OrderBuyer::getDefaultPersonType($siteId));
}
if (strlen($siteName) > 0) {
$APPLICATION->SetTitle(str_replace("##SITE##", $siteName, Loc::getMessage("SALE_OK_TITLE_SITE")));
} else {
$APPLICATION->SetTitle(Loc::getMessage("SALE_OK_TITLE_NO_SITE"));
}
CUtil::InitJSCore();
\Bitrix\Main\Page\Asset::getInstance()->addJs("/bitrix/js/sale/admin/order_edit.js");
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
Blocks\OrderBasket::getCatalogMeasures();
// context menu
$aMenu = array();
$aMenu[] = array("ICON" => "btn_list", "TEXT" => Loc::getMessage("SALE_OK_LIST"), "TITLE" => Loc::getMessage("SALE_OK_LIST_TITLE"), "LINK" => "/bitrix/admin/sale_order.php?lang=" . LANGUAGE_ID . GetFilterParams("filter_"));
$context = new CAdminContextMenu($aMenu);
示例5: createOrderFromForm
/**
* @param array $formData
* @param $creatorUserId
* @param bool $createUserIfNeed
* @param array $files
* @param Result &$opResult
* @return Order|static
* @throws ArgumentNullException
* @throws SystemException
*/
public static function createOrderFromForm(array $formData, $creatorUserId, $createUserIfNeed = true, array $files = array(), Result &$opResult)
{
if (!isset($formData["SITE_ID"]) || strlen($formData["SITE_ID"]) <= 0) {
throw new ArgumentNullException('formData["SITE_ID"]');
}
$order = Order::create($formData["SITE_ID"]);
/** @var \Bitrix\Sale\Result $res */
$res = self::fillSimpleFields($order, $formData, $creatorUserId);
if (!$res->isSuccess()) {
$opResult->addErrors($res->getErrors());
}
$propCollection = $order->getPropertyCollection();
$res = $propCollection->setValuesFromPost($formData, $files);
if (!$res->isSuccess()) {
$opResult->addErrors($res->getErrors());
}
//creates new user if need
$order->setFieldNoDemand("USER_ID", self::getUserId($order, $formData, $createUserIfNeed, $opResult));
$fUserId = null;
if ($order->getUserId() > 0) {
$fUserId = Fuser::getIdByUserId($order->getUserId());
}
//init basket
if (isset($formData["PRODUCT"]) && is_array($formData["PRODUCT"])) {
$basket = \Bitrix\Sale\Basket::create($formData["SITE_ID"]);
$basket->setFUserId($fUserId);
sortByColumn($formData["PRODUCT"], array("BASE_PRICE" => SORT_DESC, "PRICE" => SORT_DESC));
foreach ($formData["PRODUCT"] as $basketCode => $productData) {
if ($productData["IS_SET_ITEM"] == "Y") {
continue;
}
if (!isset($productData["PROPS"]) || !is_array($productData["PROPS"])) {
$productData["PROPS"] = array();
}
$item = $basket->getExistsItem($productData["MODULE"], $productData["OFFER_ID"], $productData["PROPS"]);
if ($item == null && $basketCode != "new") {
$item = $basket->getItemByBasketCode($basketCode);
}
if ($item && $item->isBundleChild()) {
$item = null;
}
if ($item) {
//Let's extract cached provider product data from field
if (!empty($productData["PROVIDER_DATA"])) {
$providerData = unserialize($productData["PROVIDER_DATA"]);
if (is_array($providerData) && !empty($providerData)) {
self::setProviderTrustData($item, $order, $providerData);
}
}
if (!empty($productData["SET_ITEMS_DATA"])) {
$productData["SET_ITEMS"] = unserialize($productData["SET_ITEMS_DATA"]);
}
$res = $item->setField("QUANTITY", $item->getField("QUANTITY") + $productData["QUANTITY"]);
if (!$res->isSuccess()) {
$opResult->addErrors($res->getErrors());
}
} else {
$setBasketCode = $basketCode != "new" ? $basketCode : null;
$item = $basket->createItem($productData["MODULE"], $productData["OFFER_ID"], $setBasketCode);
if ($basketCode != $productData["BASKET_CODE"]) {
$productData["BASKET_CODE"] = $item->getBasketCode();
}
$needDataUpdate = false;
if ($basketCode == "new") {
$opResult->setData(array("NEW_ITEM_BASKET_CODE" => $productData["BASKET_CODE"]));
$needDataUpdate = true;
}
$fbRes = self::fillBasketItem($item, $productData, $order, $basket, $needDataUpdate);
if (!$fbRes->isSuccess()) {
$opResult->addErrors($fbRes->getErrors());
}
if (isset($productData["PROPS"]) && !empty($productData["PROPS"]) && is_array($productData["PROPS"])) {
/** @var \Bitrix\Sale\BasketPropertiesCollection $property */
$property = $item->getPropertyCollection();
$property->setProperty($productData["PROPS"]);
}
}
}
$res = $order->setBasket($basket);
if (!$res->isSuccess()) {
$opResult->addErrors($res->getErrors());
}
if (isset($formData["DISCOUNTS"]) && is_array($formData["DISCOUNTS"])) {
$order->getDiscount()->setApplyResult($formData["DISCOUNTS"]);
}
} else {
$opResult->addError(new EntityError(Loc::getMessage("SALE_ORDEREDIT_ERROR_NO_PRODUCTS")));
}
return $order;
}
示例6: getPropertyByCode
}
function getPropertyByCode($propertyCollection, $code)
{
foreach ($propertyCollection as $property) {
if ($property->getField('CODE') == $code) {
return $property;
}
}
}
$siteId = \Bitrix\Main\Context::getCurrent()->getSite();
$fio = 'Пупкин Василий';
$phone = '9511111111';
$email = 'pupkin@mail.ru';
$currencyCode = Option::get('sale', 'default_currency', 'RUB');
DiscountCouponsManager::init();
$order = Order::create($siteId, \CSaleUser::GetAnonymousUserID());
$order->setPersonTypeId(1);
$basket = Sale\Basket::loadItemsForFUser(\CSaleBasket::GetBasketUserID(), $siteId)->getOrderableItems();
/* Действия над товарами
$basketItems = $basket->getBasketItems();
foreach ($basketItems as $basketItem) {
}
*/
$order->setBasket($basket);
/*Shipment*/
$shipmentCollection = $order->getShipmentCollection();
$shipment = $shipmentCollection->createItem();
$shipment->setFields(['DELIVERY_ID' => 1, 'CURRENCY' => $currencyCode]);
/**/
/*Payment*/