Ejemplo n.º 1
0
 /**
  * @param CollectableEntity $item
  * @return CollectableEntity
  * @throws Main\ArgumentTypeException
  */
 protected function addItem(CollectableEntity $item)
 {
     $this->index++;
     $item->setInternalIndex($this->index);
     $this->collection[$this->index] = $item;
     /** @var Main\Entity\Event $event */
     $event = new Main\Event('sale', 'OnCollectionAddItem', array('COLLECTION' => $this->collection, 'ENTITY' => $item));
     $event->send();
     return $item;
 }
Ejemplo n.º 2
0
 protected function __construct(array $property = null, array $value = null, array $relation = null)
 {
     if (!$property && !$value) {
         throw new SystemException('invalid arguments', 0, __FILE__, __LINE__);
     }
     if ($property) {
         if (is_array($property['SETTINGS'])) {
             $property += $property['SETTINGS'];
             unset($property['SETTINGS']);
         }
     } else {
         $property = array('TYPE' => 'STRING', 'PROPS_GROUP_ID' => 0, 'NAME' => $value['NAME'], 'CODE' => $value['CODE']);
     }
     if (!$value) {
         $value = array('ORDER_PROPS_ID' => $property['ID'], 'NAME' => $property['NAME'], 'CODE' => $property['CODE']);
     }
     if (!empty($relation)) {
         $property['RELATION'] = $relation;
     }
     switch ($property['TYPE']) {
         case 'ENUM':
             if ($propertyId = $property['ID']) {
                 $property['OPTIONS'] = static::loadOptions($propertyId);
             }
             break;
         case 'FILE':
             if ($defaultValue =& $property['DEFAULT_VALUE']) {
                 $defaultValue = Input\File::loadInfo($defaultValue);
             }
             if ($orderValue =& $value['VALUE']) {
                 $orderValue = Input\File::loadInfo($orderValue);
             }
             break;
     }
     $this->property = $property;
     $this->savedValue = Input\File::getValue($property, $value['VALUE']);
     parent::__construct($value);
     //TODO field
 }
Ejemplo n.º 3
0
 /**
  * @param array $fields			Fields list.
  * @return Result
  */
 public function setFields(array $fields)
 {
     foreach ($fields as $name => $value) {
         if ($this->isCalculatedField($name)) {
             $this->calculatedFields[$name] = $value;
             unset($fields[$name]);
         }
     }
     if (array_key_exists('CUSTOM_PRICE', $fields) && strval($fields['CUSTOM_PRICE']) != '') {
         $this->setField('CUSTOM_PRICE', $fields['CUSTOM_PRICE']);
     }
     return parent::setFields($fields);
 }
Ejemplo n.º 4
0
 /**
  * @param string $name
  * @param mixed $oldValue
  * @param mixed $value
  * @return Result
  * @throws Main\NotSupportedException
  */
 protected function onFieldModify($name, $oldValue, $value)
 {
     global $USER;
     if ($name == "MARKED") {
         if ($oldValue != "Y") {
             $this->setField('DATE_MARKED', new Main\Type\DateTime());
             $this->setField('EMP_MARKED_ID', $USER->GetID());
         } elseif ($value == "N") {
             $this->setField('REASON_MARKED', '');
         }
     }
     if ($name == "ALLOW_DELIVERY") {
         if ($oldValue != $value) {
             $this->setField('DATE_ALLOW_DELIVERY', new Main\Type\DateTime());
             $this->setField('EMP_ALLOW_DELIVERY_ID', $USER->GetID());
         }
     }
     if ($name == "DEDUCTED") {
         if ($oldValue != $value) {
             $this->setField('DATE_DEDUCTED', new Main\Type\DateTime());
             $this->setField('EMP_DEDUCTED_ID', $USER->GetID());
         }
     }
     return parent::onFieldModify($name, $oldValue, $value);
 }
Ejemplo n.º 5
0
 protected function onFieldModify($name, $oldValue, $value)
 {
     $r = parent::onFieldModify($name, $oldValue, $value);
     if ($r->isSuccess(true)) {
         if ($name === 'BASE_PRICE' || $name === 'DISCOUNT_PRICE') {
             if ($this->getField('CUSTOM_PRICE') !== 'Y') {
                 $r1 = $this->setField('PRICE', $this->getField('BASE_PRICE') - $this->getField('DISCOUNT_PRICE'));
                 if (!$r1->isSuccess()) {
                     $r->addErrors($r1->getErrors());
                 }
             }
         }
     }
     return $r;
 }
Ejemplo n.º 6
0
 /**
  * @return bool
  */
 public function isChanged()
 {
     if (parent::isChanged()) {
         return true;
     }
     /** @var ShipmentItemStoreCollection $shipmentItemCollection */
     if ($shipmentItemStoreCollection = $this->getShipmentItemStoreCollection()) {
         if ($shipmentItemStoreCollection->isChanged()) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 7
0
 /**
  * @param $name
  * @param $value
  * @return Result
  * @throws Main\ArgumentOutOfRangeException
  * @throws Main\NotImplementedException
  * @throws \Exception
  */
 public function setField($name, $value)
 {
     if ($name == "PAY_SYSTEM_ID") {
         if (intval($value) > 0 && !PaySystemService::isExist($value)) {
             $result = new Result();
             $result->addError(new ResultError(Loc::getMessage('SALE_PAYMENT_WRONG_PAYMENT_SERVICE'), 'SALE_PAYMENT_WRONG_PAYMENT_SERVICE'));
             return $result;
         }
         /** @var PaymentCollection $paymentCollection */
         if (!($paymentCollection = $this->getCollection())) {
             throw new Main\ObjectNotFoundException('Entity "PaymentCollection" not found');
         }
         if (count($paymentCollection) == 1) {
             /** @var Order $order */
             if ($order = $paymentCollection->getOrder()) {
                 if (strval($order->getField('PAY_SYSTEM_ID')) == '') {
                     $order->setFieldNoDemand('PAY_SYSTEM_ID', intval($value));
                 }
             }
         }
     }
     return parent::setField($name, $value);
 }
Ejemplo n.º 8
0
 protected function __construct(array $fields = array())
 {
     parent::__construct($fields);
 }