Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basketitem.php
1<?php
8namespace Bitrix\Sale;
9
11use Bitrix\Main;
19
20Loc::loadMessages(__FILE__);
21
27{
28 public const TYPE_SET = 1;
29 public const TYPE_SERVICE = 2;
30
32 private $bundleCollection = null;
33
36
40 public static function getRegistryType()
41 {
43 }
44
51 public function save()
52 {
53 $result = parent::save();
54 if (!$result->isSuccess())
55 {
56 return $result;
57 }
58
59 $reserveCollection = $this->getReserveQuantityCollection();
60 if ($reserveCollection)
61 {
62 $r = $reserveCollection->save();
63 if (!$r->isSuccess())
64 {
65 return $result->addErrors($r->getErrors());
66 }
67 }
68
69 if ($this->isBundleParent())
70 {
71 $bundleCollection = $this->getBundleCollection();
72 $itemsFromDb = [];
73
74 $id = $this->getId();
75 if ($id != 0)
76 {
77 $register = Registry::getInstance(static::getRegistryType());
79 $basketClassName = $register->getBasketClassName();
80
81 $itemsFromDbList = $basketClassName::getList(
82 [
83 'select' => ['ID'],
84 'filter' => ['SET_PARENT_ID' => $id],
85 ]
86 );
87 while ($itemsFromDbItem = $itemsFromDbList->fetch())
88 {
89 if ($itemsFromDbItem['ID'] == $id)
90 continue;
91
92 $itemsFromDb[$itemsFromDbItem['ID']] = true;
93 }
94 }
95
97 foreach ($bundleCollection as $bundleItem)
98 {
99 $parentId = (int)$bundleItem->getField('SET_PARENT_ID');
100 if ($parentId <= 0)
101 $bundleItem->setFieldNoDemand('SET_PARENT_ID', $id);
102
103 $saveResult = $bundleItem->save();
104 if (!$saveResult->isSuccess())
105 $result->addErrors($saveResult->getErrors());
106
107 if (isset($itemsFromDb[$bundleItem->getId()]))
108 unset($itemsFromDb[$bundleItem->getId()]);
109 }
110
111 foreach ($itemsFromDb as $id => $value)
112 {
113 $this->deleteInternal($id);
114 }
115 }
116
117 return $result;
118 }
119
128 protected function add()
129 {
130 $logFields = $this->getLoggedFields();
131
132 $result = parent::add();
133
135 $collection = $this->getCollection();
136
138 if (!$basket = $collection->getBasket())
139 {
140 throw new Main\ObjectNotFoundException('Entity "Basket" not found');
141 }
142
143 if ($basket->getOrderId() > 0)
144 {
145 $registry = Registry::getInstance(static::getRegistryType());
147 $orderHistory = $registry->getOrderHistoryClassName();
148
149 if (!$result->isSuccess())
150 {
151 $orderHistory::addAction(
152 'BASKET',
153 $basket->getOrderId(),
154 'BASKET_ITEM_ADD_ERROR',
155 null,
156 $this,
157 ["ERROR" => $result->getErrorMessages()]
158 );
159 }
160 else
161 {
162 $orderHistory::addLog(
163 'BASKET',
164 $basket->getOrderId(),
165 "BASKET_ITEM_ADD",
166 $this->getId(),
167 $this,
168 $logFields,
169 $orderHistory::SALE_ORDER_HISTORY_LOG_LEVEL_1
170 );
171
172 $orderHistory::addAction(
173 'BASKET',
174 $basket->getOrderId(),
175 "BASKET_SAVED",
176 $this->getId(),
177 $this,
178 [],
179 $orderHistory::SALE_ORDER_HISTORY_ACTION_LOG_LEVEL_1
180 );
181 }
182 }
183
184 return $result;
185 }
186
196 protected function update()
197 {
198 $registry = Registry::getInstance(static::getRegistryType());
200 $orderHistory = $registry->getOrderHistoryClassName();
201
203 $collection = $this->getCollection();
204
206 if (!$basket = $collection->getBasket())
207 {
208 throw new Main\ObjectNotFoundException('Entity "Basket" not found');
209 }
210
211 $logFields = $this->getLoggedFields();
212
213 $result = parent::update();
214
215 if (!$result->isSuccess())
216 {
217 if ($basket->getOrderId() > 0)
218 {
219 $orderHistory::addAction(
220 'BASKET',
221 $basket->getOrderId(),
222 'BASKET_ITEM_UPDATE_ERROR',
223 null,
224 $this,
225 ["ERROR" => $result->getErrorMessages()]
226 );
227 }
228 }
229 else
230 {
231 $orderHistory::addLog(
232 'BASKET',
233 $basket->getOrderId(),
234 "BASKET_ITEM_UPDATE",
235 $this->getId(),
236 $this,
237 $logFields,
238 $orderHistory::SALE_ORDER_HISTORY_LOG_LEVEL_1
239 );
240
241 $orderHistory::addAction(
242 'BASKET',
243 $basket->getOrderId(),
244 "BASKET_SAVED",
245 $this->getId(),
246 $this,
247 [],
248 $orderHistory::SALE_ORDER_HISTORY_ACTION_LOG_LEVEL_1
249 );
250 }
251
252 return $result;
253 }
254
261 private function getLoggedFields()
262 {
264 $basket = $this->getCollection();
265
266 $orderId = $basket->getOrderId();
267
268 $changeMeaningfulFields = [
269 "PRODUCT_ID",
270 "QUANTITY",
271 "PRICE",
272 "DISCOUNT_VALUE",
273 "VAT_RATE",
274 "NAME",
275 ];
276
277 $logFields = [];
278 if ($orderId > 0 && $this->isChanged())
279 {
280 $itemValues = $this->getFields();
281 $originalValues = $itemValues->getOriginalValues();
282
283 foreach($originalValues as $originalFieldName => $originalFieldValue)
284 {
285 if (in_array($originalFieldName, $changeMeaningfulFields) && $this->getField($originalFieldName) != $originalFieldValue)
286 {
287 $logFields[$originalFieldName] = $this->getField($originalFieldName);
288 $logFields['OLD_'.$originalFieldName] = $originalFieldValue;
289 }
290 }
291 }
292
293 return $logFields;
294 }
295
301 protected function checkBeforeDelete()
302 {
303 $result = new Result();
304
306 $collection = $this->getCollection();
307
309 $order = $collection->getBasket()->getOrder();
310
311 if ($order)
312 {
314 foreach ($order->getShipmentCollection() as $shipment)
315 {
316 if ($shipment->isSystem())
317 {
318 continue;
319 }
320
322 if ($shipmentItemCollection = $shipment->getShipmentItemCollection())
323 {
324 if ($shipmentItemCollection->getItemByBasketCode($this->getBasketCode())
325 && $shipment->isShipped()
326 )
327 {
328 $messageCode = 'SALE_BASKET_ITEM_REMOVE_IMPOSSIBLE_BECAUSE_SHIPPED';
329 if ($this->isService())
330 {
331 $messageCode = 'SALE_BASKET_ITEM_REMOVE_IMPOSSIBLE_BECAUSE_SERVICE_SHIPPED';
332 }
333
334 $result->addError(
335 new ResultError(
337 $messageCode,
338 [
339 '#PRODUCT_NAME#' => $this->getField('NAME'),
340 ]
341 ),
342 'SALE_BASKET_ITEM_REMOVE_IMPOSSIBLE_BECAUSE_SHIPPED'
343 )
344 );
345
346 return $result;
347 }
348 }
349 }
350 }
351
352 return $result;
353 }
354
361 public function delete()
362 {
363 $result = new Result();
364
365 $deleteResult = parent::delete();
366 if (!$deleteResult->isSuccess())
367 {
368 $result->addErrors($deleteResult->getErrors());
369 return $result;
370 }
371
372 if ($this->isBundleParent())
373 {
374 $bundleCollection = $this->getBundleCollection();
375 if ($bundleCollection)
376 {
378 foreach ($bundleCollection as $bundleItem)
379 {
380 $deleteResult = $bundleItem->delete();
381 if (!$deleteResult->isSuccess())
382 {
383 $result->addErrors($deleteResult->getErrors());
384 }
385 }
386 }
387 }
388
390 $reserveQuantityCollection = $this->getReserveQuantityCollection();
392 {
394 foreach ($reserveQuantityCollection as $reserve)
395 {
396 $r = $reserve->delete();
397 if (!$r->isSuccess())
398 {
399 $result->addErrors($r->getErrors());
400 }
401 }
402 }
403
404 return $result;
405 }
406
415 public function getReserveQuantityCollection()
416 {
417 if (!$this->isReservableItem())
418 {
419 return null;
420 }
421
422 if ($this->reserveQuantityCollection === null)
423 {
424 $registry = Registry::getInstance(static::getRegistryType());
425
427 $reserveCollectionClassName = $registry->getReserveCollectionClassName();
428
429 $this->reserveQuantityCollection = $reserveCollectionClassName::load($this);
430 }
431
433 }
434
440 private function clearBundleItemFields(array $fields)
441 {
442 if (!empty($fields))
443 {
444 $settableFields = static::getAllFields();
445
446 foreach ($fields as $name => $value)
447 {
448 if (!isset($settableFields[$name]))
449 {
450 unset($fields[$name]);
451 }
452 }
453 }
454
455 return $fields;
456 }
457
461 public function getParentBasketItem()
462 {
463 $collection = $this->getCollection();
464
465 if ($collection instanceof BundleCollection)
466 {
467 return $collection->getParentBasketItem();
468 }
469
470 return null;
471 }
472
477 public function getParentBasketItemId()
478 {
479 if ($parentBasketItem = $this->getParentBasketItem())
480 {
481 return $parentBasketItem->getId();
482 }
483 return null;
484 }
485
490 public function isBundleParent()
491 {
492 return (int)$this->getField('TYPE') === static::TYPE_SET;
493 }
494
498 public function isBundleChild()
499 {
500 return $this->collection instanceof BundleCollection;
501 }
502
514 public function getBundleBaseQuantity()
515 {
516 if ($this->isBundleParent())
517 {
519 if (!($bundleCollection = $this->getBundleCollection()))
520 {
521 throw new ObjectNotFoundException('Entity "BasketBundleCollection" not found');
522 }
523
524 $bundleChildList = [];
525 $result = [];
526
527 $originalQuantity = $this->getQuantity();
528 $originalValues = $this->fields->getOriginalValues();
529 if (array_key_exists('QUANTITY', $originalValues) && $originalValues['QUANTITY'] !== null)
530 {
531 $originalQuantity = $originalValues['QUANTITY'];
532 }
534 foreach ($bundleCollection as $bundleBasketItem)
535 {
536 $originalBundleQuantity = $bundleBasketItem->getQuantity();
537 $originalBundleValues = $bundleBasketItem->getFields()->getOriginalValues();
538 if (array_key_exists('QUANTITY', $originalBundleValues) && $originalBundleValues['QUANTITY'] !== null)
539 {
540 $originalBundleQuantity = $originalBundleValues['QUANTITY'];
541 }
542
543 if ($originalQuantity > 0)
544 {
545 $bundleQuantity = $originalBundleQuantity / $originalQuantity;
546 }
547 else
548 {
549 $bundleQuantity = 0;
550 }
551
552 $bundleChildList[]["ITEMS"][] = [
553 "PRODUCT_ID" => $bundleBasketItem->getProductId(),
554 "QUANTITY" => $bundleQuantity
555 ];
556
557 }
558
559 if (empty($bundleChildList))
560 return false;
561
562 foreach ($bundleChildList as $bundleBasketListDat)
563 {
564 foreach ($bundleBasketListDat["ITEMS"] as $bundleDat)
565 {
566 $result[$bundleDat['PRODUCT_ID']] = $bundleDat['QUANTITY'];
567 }
568 }
569
570 return $result;
571 }
572
573 return false;
574 }
575
587 public function getBundleCollection()
588 {
589 if ($this->bundleCollection === null)
590 {
591 if ($this->getId() > 0)
592 {
593 $this->bundleCollection = $this->loadBundleCollectionFromDb();
594 }
595 else
596 {
597 $this->bundleCollection = $this->loadBundleCollectionFromProvider();
598 }
599 }
600
601 return $this->bundleCollection;
602 }
603
609 public function createBundleCollection()
610 {
611 if ($this->bundleCollection === null)
612 {
613 $registry = Registry::getInstance(static::getRegistryType());
615 $bundleClassName = $registry->getBundleCollectionClassName();
616
617 $this->bundleCollection = $bundleClassName::createBundleCollectionObject();
618 $this->bundleCollection->setParentBasketItem($this);
619
620 $this->setField('TYPE', static::TYPE_SET);
621 }
622
623 return $this->bundleCollection;
624 }
625
632 protected function loadBundleCollectionFromDb()
633 {
634 $collection = $this->createBundleCollection();
635
636 if ($this->getId() > 0)
637 {
638 return $collection->loadFromDb(["SET_PARENT_ID" => $this->getId(), "TYPE" => false]);
639 }
640
641 return $collection;
642 }
643
655 protected function loadBundleCollectionFromProvider()
656 {
657 global $USER;
658
659 $bundleChildList = [];
660
662 if (!$basket = $this->getCollection())
663 {
664 throw new Main\ObjectNotFoundException('Entity "Basket" not found');
665 }
666
668 $order = $basket->getOrder();
669 if ($order)
670 {
671 $context = [
672 'SITE_ID' => $order->getSiteId(),
673 'USER_ID' => $order->getUserId(),
674 'CURRENCY' => $order->getCurrency(),
675 ];
676 }
677 else
678 {
679 $context = [
680 'SITE_ID' => SITE_ID,
681 'USER_ID' => $USER && $USER->GetID() > 0 ? $USER->GetID() : 0,
682 'CURRENCY' => CurrencyManager::getBaseCurrency(),
683 ];
684 }
685
686 $creator = Internals\ProviderCreator::create($context);
687 $creator->addBasketItem($this);
688 $r = $creator->getBundleItems();
689 if ($r->isSuccess())
690 {
691 $resultProductListData = $r->getData();
692 if (!empty($resultProductListData['BUNDLE_LIST']))
693 {
694 $bundleChildList = $resultProductListData['BUNDLE_LIST'];
695 }
696 }
697
698 if (empty($bundleChildList))
699 {
700 return null;
701 }
702
703 $this->bundleCollection = $this->setItemsAfterGetBundle($bundleChildList);
704 return $this->bundleCollection;
705 }
706
718 private function setItemsAfterGetBundle(array $items)
719 {
721 $bundleCollection = $this->createBundleCollection();
722 foreach ($items as $providerClassName => $products)
723 {
724 foreach ($products as $productId => $bundleBasketListDat)
725 {
726 foreach ($bundleBasketListDat["ITEMS"] as $bundleDat)
727 {
728 $bundleFields = $this->clearBundleItemFields($bundleDat);
729 unset($bundleFields['ID']);
730
731 $bundleFields['CURRENCY'] = $this->getCurrency();
732
733 if ($this->getId() > 0)
734 {
735 $bundleFields['SET_PARENT_ID'] = $this->getId();
736 }
737
739 $bundleBasketItem = static::create($bundleCollection, $bundleFields['MODULE'], $bundleFields['PRODUCT_ID']);
740
741 if (!empty($bundleDat["PROPS"]) && is_array($bundleDat["PROPS"]))
742 {
744 $property = $bundleBasketItem->getPropertyCollection();
745 $property->setProperty($bundleDat["PROPS"]);
746 }
747
748 $bundleQuantity = $bundleFields['QUANTITY'] * $this->getQuantity();
749 unset($bundleFields['QUANTITY']);
750
751 $bundleBasketItem->setFieldsNoDemand($bundleFields);
752 $bundleBasketItem->setField('QUANTITY', $bundleQuantity);
753 $bundleCollection->addItem($bundleBasketItem);
754 }
755 }
756 }
757
758 return $bundleCollection;
759 }
760
773 public function findItemByBasketCode($basketCode)
774 {
775 $item = parent::findItemByBasketCode($basketCode);
776 if ($item !== null)
777 return $item;
778
779 if ($this->isBundleParent())
780 {
783 foreach ($collection as $basketItem)
784 {
785 $item = $basketItem->findItemByBasketCode($basketCode);
786 if ($item !== null)
787 return $item;
788 }
789 }
790
791 return null;
792 }
793
806 public function findItemById($id)
807 {
808 $item = parent::findItemById($id);
809 if ($item !== null)
810 return $item;
811
812 if ($this->isBundleParent())
813 {
816 foreach ($collection as $basketItem)
817 {
818 $item = $basketItem->findItemById($id);
819 if ($item !== null)
820 return $item;
821 }
822 }
823
824 return null;
825 }
826
834 protected function addChangesToHistory($name, $oldValue = null, $value = null)
835 {
836 if ($this->getId() > 0)
837 {
838 $fields = [];
840 if (!$basket = $this->getCollection())
841 {
842 throw new ObjectNotFoundException('Entity "Basket" not found');
843 }
844
845 if ($basket->getOrder() && $basket->getOrderId() > 0)
846 {
847 if ($name == "QUANTITY")
848 {
849 if (floatval($value) == 0)
850 {
851 return;
852 }
853 $fields = [
854 'PRODUCT_ID' => $this->getProductId(),
855 'QUANTITY' => $this->getQuantity(),
856 'NAME' => $this->getField('NAME'),
857 ];
858 }
859
860 $registry = Registry::getInstance(static::getRegistryType());
861
863 $orderHistory = $registry->getOrderHistoryClassName();
864 $orderHistory::addField(
865 'BASKET',
866 $basket->getOrderId(),
867 $name,
868 $oldValue,
869 $value,
870 $this->getId(),
871 $this,
872 $fields
873 );
874 }
875 }
876 }
877
884 public static function formatQuantity($quantity)
885 {
886 $format = Config\Option::get('sale', 'format_quantity', 'AUTO');
887 if ($format == 'AUTO' || intval($format) <= 0)
888 {
889 $quantity = round($quantity, SALE_VALUE_PRECISION);
890 }
891 else
892 {
893 $quantity = number_format($quantity, intval($format), '.', '');
894 }
895
896 return $quantity;
897 }
898
902 protected static function getFieldsMap()
903 {
904 return Internals\BasketTable::getMap();
905 }
906
907 public function isChanged()
908 {
909 $isChanged = parent::isChanged();
910
911 if ($isChanged === false)
912 {
913 $reserveCollection = $this->getReserveQuantityCollection();
914 if ($reserveCollection)
915 {
916 $isChanged = $reserveCollection->isChanged();
917 }
918 }
919
920 return $isChanged;
921 }
922
937 public function createClone(\SplObjectStorage $cloneEntity)
938 {
939 if ($this->isClone() && $cloneEntity->contains($this))
940 {
941 return $cloneEntity[$this];
942 }
943
945 $basketItemClone = parent::createClone($cloneEntity);
946
948 if ($calculatedFields = $this->calculatedFields)
949 {
950 $basketItemClone->calculatedFields = $calculatedFields->createClone($cloneEntity);
951 }
952
953 if (!$cloneEntity->contains($this))
954 {
955 $cloneEntity[$this] = $basketItemClone;
956 }
957
959 if ($propertyCollection = $this->getPropertyCollection())
960 {
961 if (!$cloneEntity->contains($propertyCollection))
962 {
963 $cloneEntity[$propertyCollection] = $propertyCollection->createClone($cloneEntity);
964 }
965
966 if ($cloneEntity->contains($propertyCollection))
967 {
968 $basketItemClone->propertyCollection = $cloneEntity[$propertyCollection];
969 }
970 }
971
973 if ($reservedCollection = $this->getReserveQuantityCollection())
974 {
975 if (!$cloneEntity->contains($reservedCollection))
976 {
977 $cloneEntity[$reservedCollection] = $reservedCollection->createClone($cloneEntity);
978 }
979
980 if ($cloneEntity->contains($reservedCollection))
981 {
982 $basketItemClone->reserveQuantityCollection = $cloneEntity[$reservedCollection];
983 }
984 }
985
986 if ($this->isBundleParent())
987 {
989 if ($bundleCollection = $this->getBundleCollection())
990 {
991 if (!$cloneEntity->contains($bundleCollection))
992 {
993 $cloneEntity[$bundleCollection] = $bundleCollection->createClone($cloneEntity);
994 }
995
996 if ($cloneEntity->contains($bundleCollection))
997 {
998 $basketItemClone->bundleCollection = $cloneEntity[$bundleCollection];
999 }
1000 }
1001 }
1002
1003 return $basketItemClone;
1004 }
1005
1019 protected function onFieldModify($name, $oldValue, $value)
1020 {
1021 $result = new Result();
1022
1023 $r = parent::onFieldModify($name, $oldValue, $value);
1024 if (!$r->isSuccess())
1025 {
1026 $result->addErrors($r->getErrors());
1027 return $result;
1028 }
1029 elseif ($r->hasWarnings())
1030 {
1031 $result->addWarnings($r->getWarnings());
1032 }
1033
1034 if (!$this->isBundleParent())
1035 return $result;
1036
1037 if ($name === 'QUANTITY')
1038 {
1039 $deltaQuantity = $value - $oldValue;
1040 if ($deltaQuantity != 0)
1041 {
1042 if ($bundleCollection = $this->getBundleCollection())
1043 {
1044 $bundleBaseQuantity = $this->getBundleBaseQuantity();
1045
1047 foreach ($bundleCollection as $bundleItem)
1048 {
1049 $bundleProductId = $bundleItem->getProductId();
1050
1051 if (!isset($bundleBaseQuantity[$bundleProductId]))
1052 throw new ArgumentOutOfRangeException('bundle product id');
1053
1054 $quantity = $bundleBaseQuantity[$bundleProductId] * $value;
1055
1056 $r = $bundleItem->setField('QUANTITY', $quantity);
1057 if (!$r->isSuccess())
1058 {
1059 $result->addErrors($r->getErrors());
1060 }
1061 }
1062 }
1063 }
1064 }
1065 elseif ($name == "DELAY")
1066 {
1068 if ($bundleCollection = $this->getBundleCollection())
1069 {
1071 foreach ($bundleCollection as $bundleItem)
1072 {
1073 $r = $bundleItem->setField('DELAY', $value);
1074 if (!$r->isSuccess())
1075 {
1076 $result->addErrors($r->getErrors());
1077 }
1078 }
1079 }
1080 }
1081 elseif ($name == "CAN_BUY")
1082 {
1084 if ($bundleCollection = $this->getBundleCollection())
1085 {
1087 foreach ($bundleCollection as $bundleItem)
1088 {
1089 $r = $bundleItem->setField('CAN_BUY', $value);
1090 if (!$r->isSuccess())
1091 {
1092 $result->addErrors($r->getErrors());
1093 }
1094 }
1095 }
1096 }
1097
1098 return $result;
1099 }
1100
1111 public static function load(BasketItemCollection $basket, $data)
1112 {
1113 $bundleItems = [];
1114 if (isset($data['ITEMS']))
1115 {
1116 $bundleItems = $data['ITEMS'];
1117 unset($data['ITEMS']);
1118 }
1119
1121 $basketItem = parent::load($basket, $data);
1122
1123 if ($bundleItems)
1124 {
1125 $bundleCollection = $basketItem->createBundleCollection();
1126 $bundleCollection->loadFromArray($bundleItems);
1127 }
1128
1129 return $basketItem;
1130 }
1131
1137 protected function addInternal(array $fields)
1138 {
1139 return Internals\BasketTable::add($fields);
1140 }
1141
1148 protected function updateInternal($primary, array $fields)
1149 {
1150 return Internals\BasketTable::update($primary, $fields);
1151 }
1152
1158 protected function deleteInternal($primary)
1159 {
1160 return Internals\BasketTable::delete($primary);
1161 }
1162
1170 public function getReservedQuantity()
1171 {
1172 $reserveQuantityCollection = $this->getReserveQuantityCollection();
1173 return $reserveQuantityCollection ? $reserveQuantityCollection->getQuantity() : 0;
1174 }
1175
1176 public function isReservableItem(): bool
1177 {
1178 return !$this->isBundleParent() && !$this->isService();
1179 }
1180
1184 public function getNotPurchasedQuantity() : float
1185 {
1186 $quantity = parent::getNotPurchasedQuantity();
1187
1189 $order = $this->getCollection()->getOrder();
1190 if ($order)
1191 {
1192 $quantity -= $order->getShipmentCollection()->getBasketItemShippedQuantity($this);
1193 }
1194
1195 return $quantity;
1196 }
1197
1201 public function isService(): bool
1202 {
1203 return (int)$this->getField('TYPE') === static::TYPE_SERVICE;
1204 }
1205}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static load(BasketItemCollection $basketItemCollection, $data)
updateInternal($primary, array $fields)
addInternal(array $fields)
static formatQuantity($quantity)
static getInstance($type)
Definition registry.php:183