/** * @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); }
protected function onFieldModify($name, $oldValue, $value) { $result = new Result(); /** @var ShipmentItemCollection $shipmentItemCollection */ if (!($shipmentItemCollection = $this->getCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found'); } /** @var Shipment $shipment */ if (!($shipment = $shipmentItemCollection->getShipment())) { throw new Main\ObjectNotFoundException('Entity "Shipment" not found'); } if ($shipment->isShipped()) { $result = new Result(); $result->addError(new ResultError(Loc::getMessage('SALE_SHIPMENT_ITEM_SHIPMENT_ALREADY_SHIPPED_CANNOT_EDIT'), 'SALE_SHIPMENT_ITEM_SHIPMENT_ALREADY_SHIPPED_CANNOT_EDIT')); return $result; } if ($name == "QUANTITY") { /** @var BasketItem $basketItem */ if (!($basketItem = $this->getBasketItem())) { throw new Main\ObjectNotFoundException('Entity "BasketItem" not found'); } $deltaQuantity = $value - $oldValue; if ($deltaQuantity > 0) { /** @var ShipmentCollection $shipmentCollection */ if (!($shipmentCollection = $shipment->getCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found'); } /** @var Shipment $systemShipment */ if (!($systemShipment = $shipmentCollection->getSystemShipment())) { throw new Main\ObjectNotFoundException('Entity "System Shipment" not found'); } $systemBasketItemQuantity = $systemShipment->getBasketItemQuantity($basketItem); if ($systemBasketItemQuantity < abs($deltaQuantity)) { $errorBasketCode = $basketItem->getBasketCode(); if ($basketItem->isBundleChild()) { /** @var BasketItem $parentBasketItem */ if (!($parentBasketItem = $basketItem->getParentBasketItem())) { throw new Main\ObjectNotFoundException('Entity "Parent Basket Item" not found'); } $errorBasketCode = $parentBasketItem->getBasketCode(); } if (isset(static::$errors[$errorBasketCode][$basketItem->getField('ORDER_DELIVERY_BASKET_ID')]['STORE_QUANTITY_LARGER_ALLOWED'])) { static::$errors[$errorBasketCode][$basketItem->getField('ORDER_DELIVERY_BASKET_ID')]['STORE_QUANTITY_LARGER_ALLOWED'] += $basketItem->getQuantity(); } else { $result->addError(new ResultError(Loc::getMessage('SALE_SHIPMENT_ITEM_LESS_AVAILABLE_QUANTITY', array('#PRODUCT_NAME#' => $basketItem->getField('NAME'))), 'SALE_SHIPMENT_ITEM_LESS_AVAILABLE_QUANTITY')); static::$errors[$errorBasketCode][$basketItem->getField('ORDER_DELIVERY_BASKET_ID')]['STORE_QUANTITY_LARGER_ALLOWED'] = $basketItem->getQuantity(); } // // $result->addError(new ResultError(Loc::getMessage('SALE_SHIPMENT_ITEM_LESS_AVAILABLE_QUANTITY', array( // '#PRODUCT_NAME#' => $basketItem->getField('NAME') // )), 'SALE_SHIPMENT_ITEM_LESS_AVAILABLE_QUANTITY')); return $result; } } if ($basketItem->isBundleParent()) { $r = parent::onFieldModify($name, $oldValue, $value); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } if ($bundleCollection = $basketItem->getBundleCollection()) { $bundleBaseQuantity = $basketItem->getBundleBaseQuantity(); /** @var BasketItem $bundleBasketItem */ foreach ($bundleCollection as $bundleBasketItem) { /** @var ShipmentItem $shipmentItem */ if ($shipmentItem = $shipmentItemCollection->getItemByBasketCode($bundleBasketItem->getBasketCode())) { $bundleProductId = $bundleBasketItem->getProductId(); if (!isset($bundleBaseQuantity[$bundleProductId])) { throw new Main\ArgumentOutOfRangeException("bundle product id"); } $quantity = $bundleBaseQuantity[$bundleProductId] * $value; $r = $shipmentItem->setQuantity($quantity); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } } } if (!$this->isMathActionOnly()) { $r = $this->calculateDelivery(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } return $result; } if (!$basketItem->isBundleChild()) { if (!$this->isMathActionOnly()) { $r = $this->calculateDelivery(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } } /** @var ShipmentItemStoreCollection $shipmentItemStoreCollection */ if (!($shipmentItemStoreCollection = $this->getShipmentItemStoreCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentItemStoreCollection" not found'); } if ($value == 0) { /** @var Shipment $shipment */ if (!($shipment = $shipmentItemCollection->getShipment())) { throw new Main\ObjectNotFoundException('Entity "Shipment" not found'); } /** @var ShipmentCollection $shipmentCollection */ if (!($shipmentCollection = $shipment->getCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentCollection" not found'); } /** @var Order $order */ if (!($order = $shipmentCollection->getOrder())) { throw new Main\ObjectNotFoundException('Entity "Order" not found'); } OrderHistory::addAction('SHIPMENT', $order->getId(), 'SHIPMENT_ITEM_BASKET_REMOVED', $shipment->getId(), null, array('NAME' => $basketItem->getField('NAME'), 'PRODUCT_ID' => $basketItem->getProductId())); /** @var ShipmentItemStore $shipmentItemStore */ foreach ($shipmentItemStoreCollection as $shipmentItemStore) { $shipmentItemStore->delete(); } } else { // check barcodes /** @var ShipmentItemStoreCollection $shipmentItemStoreCollection */ if ($this->getShipmentItemStoreCollection()) { $barcodeQuantity = $shipmentItemStoreCollection->getQuantityByBasketCode($basketItem->getBasketCode()); if ($barcodeQuantity > $value) { $result->addError(new ResultError(Loc::getMessage('SALE_SHIPMENT_ITEM_BARCODE_MORE_ITEM_QUANTITY'), 'BARCODE_MORE_ITEM_QUANTITY')); return $result; } } } } return parent::onFieldModify($name, $oldValue, $value); }
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; }
/** * @param string $name * @param mixed $oldValue * @param mixed $value * @return Result * @throws Main\NotSupportedException */ protected function onFieldModify($name, $oldValue, $value) { global $USER; if ($name == "PAID") { if ($oldValue != "Y") { $this->setField('DATE_PAID', new Main\Type\DateTime()); $this->setField('EMP_PAID_ID', $USER->GetID()); } } elseif ($name == "IS_RETURN") { if ($oldValue != "Y") { // $this->setField('PAY_RETURN_DATE', new Main\Type\DateTime()); $this->setField('EMP_RETURN_ID', $USER->GetID()); } } elseif ($name == "SUM") { if ($this->isPaid()) { $result = new Result(); $result->addError(new ResultError(Loc::getMessage('SALE_PAYMENT_NOT_ALLOWED_CHANGE_SUM'), 'SALE_PAYMENT_NOT_ALLOWED_CHANGE_SUM')); return $result; } } return parent::onFieldModify($name, $oldValue, $value); }