28 private static $instance =
null;
29 private static $settings =
null;
38 if(self::$instance ===
null)
40 self::$instance =
new static();
42 return self::$instance;
45 private function __clone() {}
46 private function __construct() {}
54 if(self::$settings ===
null)
60 Option::get(
'catalog',
'enable_reservation',
'N')==
'Y')
65 if(Option::get(
"main",
"~sale_converted_15",
'N') <>
'Y')
70 if(Option::get(
"sale",
"allow_deduction_on_delivery",
"N") ==
'Y')
78 return self::$settings;
98 if(array_key_exists(self::DELIVERY_SERVICE_XMLID,
$items))
118 $documentOrder = $this->getDocumentByTypeId(
OneC\DocumentType::ORDER, $documents);
122 $agentFieldValue = $documentOrder->getFieldValues();
123 if(is_array($agentFieldValue[
'AGENT']))
126 $documentProfile->setFields($agentFieldValue[
'AGENT']);
127 $documents[] = $documentProfile;
131 foreach($documents as $document)
159 $entityTypeId = static::getParentEntityTypeId();
162 $entityTypeId = static::getPaymentCardEntityTypeId();
165 $entityTypeId = static::getPaymentCashEntityTypeId();
168 $entityTypeId = static::getPaymentCashLessEntityTypeId();
171 $entityTypeId = static::getShipmentEntityTypeId();
175 $entityTypeId = $typeId;
178 return $entityTypeId;
189 $parentEntityId =
null;
191 $item = $this->getEntityByTypeId(static::getParentEntityTypeId(),
$items);
194 $params = $item->getFieldValues();
199 $parentEntityId =
$fields[
'ID'];
203 $parentEntityId =
$fields[$item::getFieldExternalId()];
207 if(empty($parentEntityId))
212 if($item->getOwnerTypeId() <> static::getParentEntityTypeId())
214 $params = $item->getFieldValues();
217 if(!empty($parentEntityId) &&
$fields[
'ORDER_ID']<>
'')
219 if($parentEntityId <>
$fields[
'ORDER_ID'])
236 parent::configuration();
238 static::setConfig(static::DELETE_IF_NOT_FOUND_RELATED_PAYMENT_DOCUMENT);
267 if($item->getOwnerTypeId() == static::getParentEntityTypeId())
275 if($item->getOwnerTypeId() <> static::getParentEntityTypeId() && $item->getOwnerTypeId() <>
EntityType::USER_PROFILE)
297 if($itemParent->getEntityId()>0)
302 $this->save($itemParent,
$items);
306 $r = $this->onBeforeEntityModify($itemParent,
$items);
307 if($r->hasWarnings())
308 $this->marker($itemParent, $r);
320 if($itemParent->getEntityId() ==
null)
322 $params = $item->getFieldValues();
325 $personalTypeId =
$params[
'TRAITS'][
'PERSON_TYPE_ID'] = $item->resolvePersonTypeId(
$fields);
327 $property =
$params[
'ORDER_PROPS'];
328 if(!empty($property))
330 $params[
'ORDER_PROP'] = $item->getPropertyOrdersByConfig($personalTypeId,
array(), $property);
338 if(intval($personalTypeId)<=0)
339 $r->addError(
new Error(
GetMessage(
"SALE_EXCHANGE_PACKAGE_ERROR_PERSONAL_TYPE_IS_EMPTY",
array(
"#DOCUMENT_ID#"=>
$fields[
'XML_ID'])),
"PACKAGE_ERROR_PERSONAL_TYPE_IS_EPMTY"));
343 if(!$this->importableItems($item))
350 if(intval($item->getId())<=0)
351 $r->addError(
new Error(
GetMessage(
"SALE_EXCHANGE_PACKAGE_ERROR_USER_IS_EMPTY",
array(
"#DOCUMENT_ID#"=>
$fields[
'XML_ID'])),
"PACKAGE_ERROR_USER_IS_EPMTY"));
356 $paramsOrder = $itemParent->getFieldValues();
357 $fieldsOrder = &$paramsOrder[
'TRAITS'];
359 if(!empty($property))
361 $fieldsOrder[
'ORDER_PROP'] =
$params[
'ORDER_PROP'];
364 $fieldsOrder[
'USER_ID'] = $item->getId();
365 $fieldsOrder[
'PERSON_TYPE_ID'] = $personalTypeId;
366 $itemParent->setFields($paramsOrder);
371 elseif($item->getOwnerTypeId() == static::getParentEntityTypeId())
373 if(!$this->importableItems($itemParent))
383 $order = $itemParent->getEntity();
384 $params = $item->getFieldValues();
388 if(!$r->hasWarnings())
392 $r = $this->checkParentById(
$fields[
'ID'], $item);
393 if(!$r->hasWarnings())
395 $isShipped =
$order->isShipped();
401 if($item->getOwnerTypeId() == static::getShipmentEntityTypeId())
403 if(!$isShipped &&
$order->isShipped())
404 $this->onAfterShipmentModifyChangeStatusOnDelivery($itemParent);
413 $result->addErrors($r->getErrors());
418 $result->addWarnings($r->getWarnings());
425 $r = $this->onAfterEntitiesModify($itemParent,
$items);
427 $result->addErrors($r->getErrors());
428 if($r->hasWarnings())
429 $result->addWarnings($r->getWarnings());
437 $result->addErrors($r->getErrors());
438 if($r->hasWarnings())
439 $result->addWarnings($r->getWarnings());
449 private function importableItems($item)
451 if($item->getId() ==
null && !$item->isImportable())
453 switch ($item->getOwnerTypeId())
455 case static::getParentEntityTypeId():
511 $item = $this->getEntityByTypeId(static::getParentEntityTypeId(),
$items);
514 $params = $item->getFieldValues();
541 $shipmentItems =
array();
544 $order = $orderImport->getEntity();
550 switch($item->getOwnerTypeId())
552 case static::getShipmentEntityTypeId():
553 $params = $item->getFieldValues();
557 $shipmentItems[] =
$fields[
'ID'];
563 $shipmentList =
array();
564 $shipmentCollection =
$order->getShipmentCollection();
565 foreach($shipmentCollection as $shipment)
567 if($shipment->isSystem())
570 if(!in_array($shipment->getId(), $shipmentItems))
571 $shipmentList[$shipment->getId()] = $shipment;
574 if(!empty($shipmentList))
576 foreach($shipmentList as $id=>$shipment)
582 $item = $this->entityFactoryCreate($typeId);
585 $collision = $item->getLoadedCollision();
587 $collision->resolve($item);
588 if(!$item->hasCollisionErrors())
597 $collisions = $item->getCollisions();
598 $item->markedEntityCollisions($collisions);
634 $paymentItems =
array();
637 $order = $orderImport->getEntity();
643 switch($item->getOwnerTypeId())
645 case static::getPaymentCardEntityTypeId():
648 $params = $item->getFieldValues();
652 $paymentItems[] =
$fields[
'ID'];
658 $paymentList =
array();
662 if(!in_array(
$payment->getId(), $paymentItems))
666 if(!empty($paymentList))
668 foreach($paymentList as $id=>
$payment)
679 protected function paymentDelete(Payment
$payment)
688 $item = $this->entityFactoryCreate($typeId);
691 $collision = $item->getLoadedCollision();
693 $collision->resolve($item);
694 if(!$item->hasCollisionErrors())
703 $collisions = $item->getCollisions();
704 $item->markedEntityCollisions($collisions);
718 protected function onBeforeBasketModify(Exchange\Entity\OrderImport $orderImport,
$items)
720 $basketItems =
array();
723 $order = $orderImport->getEntity();
725 throw new ArgumentNullException(
'Order');
727 $basket =
$order->getBasket();
731 switch($item->getOwnerTypeId())
733 case static::getParentEntityTypeId():
734 $params = $item->getFieldValues();
735 $basketItems =
$params[
'ITEMS'];
740 $basketItemsIndex = $orderImport->calculateDeltaQuantity($basket, $basketItems);
742 $result = $orderImport->synchronizeQuantityBasketItems($basketItemsIndex);
754 protected function onBeforeEntityModify(Exchange\Entity\OrderImport $orderImport,
array $items)
757 $paymentResult =
new Result();
764 $basketItemsResult = $this->onBeforeBasketModify($orderImport,
$items);
766 if(static::$config & static::DELETE_IF_NOT_FOUND_RELATED_PAYMENT_DOCUMENT)
768 $paymentResult = $this->onBeforePaymentCollectionModify($orderImport,
$items);
769 if(!$paymentResult->isSuccess())
770 $result->addWarnings($paymentResult->getErrors());
773 $shipmentResult = $this->onBeforeShipmentCollectionModify($orderImport,
$items);
775 if(!$shipmentResult->isSuccess())
776 $result->addWarnings($shipmentResult->getErrors());
778 if(!$basketItemsResult->isSuccess() || !$shipmentResult->isSuccess() || !$paymentResult->isSuccess())
779 $result->addWarning(
new ResultWarning(
GetMessage(
'SALE_EXCHANGE_PACKAGE_ERROR_ORDER_CANNOT_UPDATE'),
"PACKAGE_ERROR_ORDER_CANNOT_UPDATE"));
790 protected function onAfterShipmentModifyChangeStatusOnDelivery(Exchange\Entity\OrderImport $orderImport)
795 $order = $orderImport->getEntity();
799 $settings = $orderImport->getSettings();
800 $status = $settings->finalStatusOnDeliveryFor($orderImport->getOwnerTypeId());
813 protected function onAfterEntitiesModify(Exchange\Entity\OrderImport $orderImport,
$items)
819 if($item->getOwnerTypeId() == static::getParentEntityTypeId())
822 $order = $orderImport->getEntity();
823 $params = $item->getFieldValues();
826 if(
$fields[
'1C_PAYED_DATE'] instanceof DateTime)
835 if(
$fields[
'1C_DELIVERY_DATE'] instanceof DateTime)
853 protected function checkParentById($id, Entity\EntityImport $item)
860 if(!empty($id) && empty(
$entity))
862 switch($item->getOwnerTypeId())
864 case static::getPaymentCashEntityTypeId():
867 $result->
addWarning(new ResultWarning(
GetMessage(
"SALE_EXCHANGE_PACKAGE_ERROR_PAYMENT_IS_NOT_RELATED_TO_ORDER_OR_DELETED",
array(
"#DOCUMENT_ID#"=>$id)),
"PACKAGE_ERROR_PAYMENT_IS_NOT_RELATED_TO_ORDER_OR_DELETED"));
869 case static::getShipmentEntityTypeId():
870 $result->
addWarning(new ResultWarning(
GetMessage(
"SALE_EXCHANGE_PACKAGE_ERROR_SHIPMENT_IS_NOT_RELATED_TO_ORDER_OR_DELETED",
array(
"#DOCUMENT_ID#"=>$id)),
"PACKAGE_ERROR_SHIPMENT_IS_NOT_RELATED_TO_ORDER_OR_DELETED"));
886 if(!(
$order instanceof Order))
888 $params = $itemOrder->getFieldValues();
904 $order = $orderImport->getEntity();
906 $orderImport->setField(
'MARKED',
'Y');
921 $collisions = $item->getCollisions();
922 if (!empty($collisions))
925 $item->markedEntityCollisions($collisions);
929 return $orderImport->save();
940 if($item->hasCollisionErrors())
955 $result->addError(
new Error(
'',
'CASH_BOX_CHECK_IGNORE'));
967 $itemParent = $this->getEntityByTypeId(static::getParentEntityTypeId(),
$items);
return[Dependency::CONTAINER=> Container::class, Dependency::IBLOCK_INFO=> IblockInfo::class, Dependency::PRODUCT_CONVERTER=> ProductConverter::class, Dependency::REPOSITORY_FACADE=> Repository::class, Dependency::PRODUCT_FACTORY=> ProductFactory::class, Dependency::PRODUCT_REPOSITORY=> ProductRepository::class, ProductFactory::PRODUCT=> Product::class, Dependency::SECTION_FACTORY=> SectionFactory::class, Dependency::SECTION_REPOSITORY=> SectionRepository::class, SectionFactory::SECTION=> Section::class, SectionFactory::SECTION_COLLECTION=> SectionCollection::class, Dependency::SKU_FACTORY=> SkuFactory::class, Dependency::SKU_REPOSITORY=> SkuRepository::class, SkuFactory::SIMPLE_SKU=> SimpleSku::class, SkuFactory::SKU=> Sku::class, SkuFactory::SKU_COLLECTION=> SkuCollection::class, Dependency::PROPERTY_FACTORY=> PropertyFactory::class, Dependency::PROPERTY_REPOSITORY=> PropertyRepository::class, PropertyFactory::PROPERTY=> Property::class, PropertyFactory::PROPERTY_COLLECTION=> PropertyCollection::class, Dependency::PROPERTY_VALUE_FACTORY=> PropertyValueFactory::class, PropertyValueFactory::PROPERTY_VALUE=> PropertyValue::class, PropertyValueFactory::PROPERTY_VALUE_COLLECTION=> PropertyValueCollection::class, Dependency::PROPERTY_FEATURE_FACTORY=> PropertyFeatureFactory::class, Dependency::PROPERTY_FEATURE_REPOSITORY=> PropertyFeatureRepository::class, PropertyFeatureFactory::PROPERTY_FEATURE=> PropertyFeature::class, PropertyFeatureFactory::PROPERTY_FEATURE_COLLECTION=> PropertyFeatureCollection::class, Dependency::PRICE_FACTORY=> PriceFactory::class, Dependency::PRICE_REPOSITORY=> PriceRepository::class, PriceFactory::SIMPLE_PRICE=> SimplePrice::class, PriceFactory::QUANTITY_DEPENDENT_PRICE=> QuantityDependentPrice::class, PriceFactory::PRICE_COLLECTION=> PriceCollection::class, Dependency::IMAGE_FACTORY=> ImageFactory::class, Dependency::IMAGE_REPOSITORY=> ImageRepository::class, ImageFactory::DETAIL_IMAGE=> DetailImage::class, ImageFactory::PREVIEW_IMAGE=> PreviewImage::class, ImageFactory::MORE_PHOTO_IMAGE=> MorePhotoImage::class, ImageFactory::IMAGE_COLLECTION=> ImageCollection::class, Dependency::MEASURE_RATIO_FACTORY=> MeasureRatioFactory::class, Dependency::MEASURE_RATIO_REPOSITORY=> MeasureRatioRepository::class, MeasureRatioFactory::SIMPLE_MEASURE_RATIO=> SimpleMeasureRatio::class, MeasureRatioFactory::MEASURE_RATIO_COLLECTION=> MeasureRatioCollection::class, Dependency::BARCODE_FACTORY=> BarcodeFactory::class, Dependency::BARCODE_REPOSITORY=> BarcodeRepository::class, BarcodeFactory::BARCODE=> Barcode::class, BarcodeFactory::BARCODE_COLLECTION=> BarcodeCollection::class, Dependency::STORE_PRODUCT_FACTORY=> StoreProductFactory::class, Dependency::STORE_PRODUCT_REPOSITORY=> StoreProductRepository::class, StoreProductFactory::STORE_PRODUCT=> StoreProduct::class, StoreProductFactory::STORE_PRODUCT_COLLECTION=> StoreProductCollection::class, 'sku.tree'=> SkuTree::class, 'integration.seo.facebook.facade'=> FacebookFacade::class, 'integration.seo.facebook.product.processor'=> FacebookProductProcessor::class, 'integration.seo.facebook.product.repository'=> FacebookProductRepository::class,]
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)