Exemplo n.º 1
0
 /**
  * Use ShipmentCollection::createShipment instead
  *
  * @param ShipmentCollection $collection
  * @param Delivery\Services\Base $deliveryService
  * @return static
  */
 public static function create(ShipmentCollection $collection, Delivery\Services\Base $deliveryService = null)
 {
     $fields = array('ALLOW_DELIVERY' => 'N', 'DEDUCTED' => 'N', 'CUSTOM_PRICE_DELIVERY' => 'N', 'MARKED' => 'N', 'CANCELED' => 'N', 'RESERVED' => 'N');
     $deliveryStatus = DeliveryStatus::getInitialStatus();
     if (!empty($deliveryStatus) && !is_array($deliveryStatus)) {
         $fields['STATUS_ID'] = $deliveryStatus;
     }
     $shipment = new static();
     $shipment->setFieldsNoDemand($fields);
     $shipment->setCollection($collection);
     if ($deliveryService !== null) {
         $shipment->setDeliveryService($deliveryService);
     }
     return $shipment;
 }
Exemplo n.º 2
0
 /**
  * @param Order $order
  * @param array $shipments
  * @return Result
  * @throws SystemException
  */
 public static function updateData(Order &$order, array $shipments)
 {
     global $USER;
     $result = new Result();
     $data = array();
     $basketResult = null;
     if (!$order) {
         $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_ORDER_NOT_FOUND')));
         return $result;
     }
     $shipmentCollection = $order->getShipmentCollection();
     $isStartField = $shipmentCollection->isStartField();
     foreach ($shipments as $item) {
         $shipmentId = intval($item['SHIPMENT_ID']);
         $isNew = $shipmentId <= 0;
         if ($isNew) {
             self::$shipment = $shipmentCollection->createItem();
         } else {
             self::$shipment = $shipmentCollection->getItemById($shipmentId);
             if (!self::$shipment) {
                 $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_SHIPMENT_NOT_FOUND')));
                 continue;
             }
         }
         self::$defaultFields = self::$shipment->getFieldValues();
         /** @var \Bitrix\Sale\BasketItem $product */
         $countItems = count(self::$shipment->getShipmentItemCollection());
         $systemShipment = $shipmentCollection->getSystemShipment();
         $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
         $products = array();
         if (!isset($item['PRODUCT']) && self::$shipment->getId() <= 0) {
             $basket = $order->getBasket();
             if ($basket) {
                 $basketItems = $basket->getBasketItems();
                 foreach ($basketItems as $product) {
                     $systemShipmentItem = $systemShipmentItemCollection->getItemByBasketCode($product->getBasketCode());
                     if ($product->isBundleChild() || !$systemShipmentItem || $systemShipmentItem->getQuantity() <= 0) {
                         continue;
                     }
                     $products[] = array('AMOUNT' => $product->getQuantity(), 'BASKET_CODE' => $product->getBasketCode());
                 }
             }
         } else {
             $products = $item['PRODUCT'];
         }
         if ($item['DEDUCTED'] == 'Y') {
             $basketResult = OrderBasketShipment::updateData($order, self::$shipment, $products);
             if (!$basketResult->isSuccess()) {
                 $result->addErrors($basketResult->getErrors());
             }
         }
         $extraServices = $item['EXTRA_SERVICES'] ? $item['EXTRA_SERVICES'] : array();
         $shipmentFields = array('COMPANY_ID' => isset($item['COMPANY_ID']) && $item['COMPANY_ID'] > 0 ? $item['COMPANY_ID'] : 0, 'DEDUCTED' => $item['DEDUCTED'], 'DELIVERY_DOC_NUM' => $item['DELIVERY_DOC_NUM'], 'TRACKING_NUMBER' => $item['TRACKING_NUMBER'], 'CURRENCY' => $order->getCurrency(), 'COMMENTS' => $item['COMMENTS'], 'STATUS_ID' => $isNew ? DeliveryStatus::getInitialStatus() : $item['STATUS_ID']);
         if ($item['DELIVERY_DOC_DATE']) {
             try {
                 $shipmentFields['DELIVERY_DOC_DATE'] = new Date($item['DELIVERY_DOC_DATE']);
             } catch (Main\ObjectException $exception) {
                 $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_UNCORRECT_FORM_DATE')));
             }
         }
         $shipmentFields['DELIVERY_ID'] = $item['PROFILE'] > 0 ? $item['PROFILE'] : $item['DELIVERY_ID'];
         try {
             $service = Services\Manager::getService($shipmentFields['DELIVERY_ID']);
             if ($service->getParentService()) {
                 $shipmentFields['DELIVERY_NAME'] = $service->getParentService()->getName() . ':' . $service->getName();
             } else {
                 $shipmentFields['DELIVERY_NAME'] = $service->getName();
             }
         } catch (Main\ArgumentNullException $e) {
             $result->addError(new EntityError(Loc::getMessage('SALE_ORDER_SHIPMENT_ERROR_NO_DELIVERY_SERVICE')));
         }
         $responsibleId = self::$shipment->getField('RESPONSIBLE_ID');
         if ($item['RESPONSIBLE_ID'] != $responsibleId || empty($responsibleId)) {
             if (isset($item['RESPONSIBLE_ID'])) {
                 $shipmentFields['RESPONSIBLE_ID'] = $item['RESPONSIBLE_ID'];
             } else {
                 $shipmentFields['RESPONSIBLE_ID'] = $order->getField('RESPONSIBLE_ID');
             }
             if (!empty($shipmentFields['RESPONSIBLE_ID'])) {
                 $shipmentFields['EMP_RESPONSIBLE_ID'] = $USER->getID();
                 $shipmentFields['DATE_RESPONSIBLE_ID'] = new DateTime();
             }
         }
         if ($extraServices) {
             self::$shipment->setExtraServices($extraServices);
         }
         $setFieldsResult = self::$shipment->setFields($shipmentFields);
         if (!$setFieldsResult->isSuccess()) {
             $result->addErrors($setFieldsResult->getErrors());
         }
         self::$shipment->setStoreId($item['DELIVERY_STORE_ID']);
         if ($item['DEDUCTED'] == 'N') {
             $basketResult = OrderBasketShipment::updateData($order, self::$shipment, $products);
             if (!$basketResult->isSuccess()) {
                 $result->addErrors($basketResult->getErrors());
             }
         }
         try {
             $priceDeliveryInfo = array();
             if ($item['CUSTOM_PRICE_DELIVERY'] != 'Y') {
                 $totalPrice = self::getDeliveryPrice(self::$shipment);
             } else {
                 $totalPrice = (double) str_replace(',', '.', $item['BASE_PRICE_DELIVERY']);
             }
         } catch (\Exception $e) {
             $totalPrice = 0;
         }
         $priceDeliveryInfo['CUSTOM_PRICE_DELIVERY'] = $item['CUSTOM_PRICE_DELIVERY'];
         $priceDeliveryInfo['BASE_PRICE_DELIVERY'] = $totalPrice;
         self::$shipment->setFields($priceDeliveryInfo);
         self::$shipment->setField('ALLOW_DELIVERY', $item['ALLOW_DELIVERY']);
         $data['SHIPMENT'][] = self::$shipment;
     }
     if ($isStartField) {
         $hasMeaningfulFields = $shipmentCollection->hasMeaningfulField();
         /** @var Result $r */
         $r = $shipmentCollection->doFinalAction($hasMeaningfulFields);
         if (!$r->isSuccess()) {
             $result->addErrors($r->getErrors());
         }
     }
     $result->setData($data);
     return $result;
 }
Exemplo n.º 3
0
				'ID'     => $deliveryGoodsStatus,
				'SORT'   => 320,
				'NOTIFY' => 'Y',
				'LANG'   => $statusLanguages[$deliveryGoodsStatus],
			));

			DeliveryStatus::install(array(
				'ID'     => $deliveryTransportStatus,
				'SORT'   => 330,
				'NOTIFY' => 'Y',
				'LANG'   => $statusLanguages[$deliveryTransportStatus],
			));

			DeliveryStatus::install(array(
				'ID'     => $deliveryShipmentStatus,
				'SORT'   => 340,
				'NOTIFY' => 'Y',
				'LANG'   => $statusLanguages[$deliveryShipmentStatus],
			));
		}
		else
		{
			$bStatusP = false;
			$dbStatus = CSaleStatus::GetList(Array("SORT" => "ASC"));
			while($arStatus = $dbStatus->Fetch())
			{
				$arFields = Array();
				foreach($arLanguages as $langID)
				{
					WizardServices::IncludeServiceLang("step1.php", $langID);
					$arFields["LANG"][] = Array("LID" => $langID, "NAME" => GetMessage("WIZ_SALE_STATUS_".$arStatus["ID"]), "DESCRIPTION" => GetMessage("WIZ_SALE_STATUS_DESCRIPTION_".$arStatus["ID"]));
				}
Exemplo n.º 4
0
while ($row = $result->Fetch()) {
    if ($row['GROUP_ID'] > 2) {
        $saleGroupIds[] = $row['GROUP_ID'];
    }
}
if ($saleGroupIds) {
    $result = GroupTable::getList(array('select' => array('ID', 'NAME'), 'filter' => array('=ID' => $saleGroupIds), 'order' => array('C_SORT' => 'ASC', 'ID' => 'ASC')));
    while ($row = $result->fetch()) {
        $groups[$row['ID']] = $row['NAME'];
    }
}
// A D D / U P D A T E /////////////////////////////////////////////////////////////////////////////////////////////////
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !$readOnly && check_bitrix_sessid() && ($_POST['save'] || $_POST['apply'])) {
    $errors = array();
    $statusType = $_REQUEST['TYPE'] == 'O' ? 'O' : 'D';
    $lockedStatusList = array("O" => array(\Bitrix\Sale\OrderStatus::getInitialStatus(), \Bitrix\Sale\OrderStatus::getFinalStatus()), "D" => array(\Bitrix\Sale\DeliveryStatus::getInitialStatus(), \Bitrix\Sale\DeliveryStatus::getFinalStatus()));
    if ($statusId) {
        foreach ($lockedStatusList as $lockStatusType => $lockStatusIdList) {
            foreach ($lockStatusIdList as $lockStatusId) {
                if ($lockStatusId == $statusId && $statusType != $lockStatusType) {
                    $errors[] = Loc::getMessage('SALE_STATUS_WRONG_TYPE', array('#STATUS_ID#' => htmlspecialcharsEx($statusId), '#STATUS_TYPE#' => Loc::getMessage('SSEN_TYPE_' . $statusType)));
                    break;
                }
            }
        }
    }
    // prepare & check status
    $status = array('TYPE' => $statusType, 'SORT' => ($statusSort = intval($_POST['SORT'])) ? $statusSort : 100, 'NOTIFY' => $_POST['NOTIFY'] ? 'Y' : 'N');
    $isNew = true;
    $result = new \Bitrix\Main\Entity\Result();
    if ($statusId) {