Ejemplo n.º 1
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\Object $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order\Shipment\Item $object */
     if (!$object->getParentId() && $object->getShipment()) {
         $object->setParentId($object->getShipment()->getId());
     }
     return parent::_beforeSave($object);
 }
Ejemplo n.º 2
0
 /**
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /**@var $object \Magento\Sales\Model\Order\Creditmemo\Item*/
     if (!$object->getParentId() && $object->getCreditmemo()) {
         $object->setParentId($object->getCreditmemo()->getId());
     }
     return parent::_beforeSave($object);
 }
Ejemplo n.º 3
0
 /**
  * Perform actions after object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order\Invoice\Item $object */
     if (null == !$object->getOrderItem()) {
         $object->getOrderItem()->save();
     }
     return parent::_afterSave($object);
 }
Ejemplo n.º 4
0
 /**
  * Performs validation before save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     parent::_beforeSave($object);
     $errors = $this->validator->validate($object);
     if (!empty($errors)) {
         throw new \Magento\Framework\Model\Exception(__("Cannot save comment") . ":\n" . implode("\n", $errors));
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     parent::_beforeSave($object);
     $warnings = $this->validator->validate($object);
     if (!empty($warnings)) {
         throw new \Magento\Framework\Exception\LocalizedException(__("Cannot save comment:\n%1", implode("\n", $warnings)));
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\Object $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /**@var $object \Magento\Sales\Model\Order\Payment */
     parent::_beforeSave($object);
     if (!$object->getParentId() && $object->getOrder()) {
         $object->setParentId($object->getOrder()->getId());
     }
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * Performs validation before save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /**@var $object \Magento\Sales\Model\Order\Creditmemo\Comment*/
     if (!$object->getParentId() && $object->getCreditmemo()) {
         $object->setParentId($object->getCreditmemo()->getId());
     }
     parent::_beforeSave($object);
     $errors = $this->validator->validate($object);
     if (!empty($errors)) {
         throw new \Magento\Framework\Exception\LocalizedException(__("Cannot save comment:\n%1", implode("\n", $errors)));
     }
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Perform actions after object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order\Creditmemo $object */
     if (null !== $object->getItems()) {
         foreach ($object->getItems() as $item) {
             $item->setParentId($object->getId());
             $item->save();
         }
     }
     if (null !== $object->getComments()) {
         foreach ($object->getComments() as $comment) {
             $comment->save();
         }
     }
     return parent::_afterSave($object);
 }
Ejemplo n.º 9
0
 /**
  * @param Resource $resource
  * @param DateTime $dateTime
  * @param Attribute $attribute
  * @param SalesIncrement $salesIncrement
  * @param InvoiceGrid $gridAggregator
  */
 public function __construct(Resource $resource, DateTime $dateTime, Attribute $attribute, SalesIncrement $salesIncrement, InvoiceGrid $gridAggregator)
 {
     parent::__construct($resource, $dateTime, $attribute, $salesIncrement, $gridAggregator);
 }
Ejemplo n.º 10
0
 /**
  * Update related grid table after object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\Object $object
  * @return \Magento\Framework\Model\Resource\Db\AbstractDb
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $resource = parent::_afterSave($object);
     if ($object->hasDataChanges() && $object->getOrderId()) {
         $this->gridPool->refreshByOrderId($object->getOrderId());
     }
     return $resource;
 }
Ejemplo n.º 11
0
 /**
  * Lookup for parent_id in already saved transactions of this payment by the order_id
  * Also serialize additional information, if any
  *
  * @param \Magento\Sales\Model\Order\Payment\Transaction $transaction
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transaction)
 {
     $parentTxnId = $transaction->getData('parent_txn_id');
     $txnId = $transaction->getData('txn_id');
     $orderId = $transaction->getData('order_id');
     $paymentId = $transaction->getData('payment_id');
     $idFieldName = $this->getIdFieldName();
     if ($parentTxnId) {
         if (!$txnId || !$orderId || !$paymentId) {
             throw new \Magento\Framework\Model\Exception(__('We don\'t have enough information to save the parent transaction ID.'));
         }
         $parentId = (int) $this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName);
         if ($parentId) {
             $transaction->setData('parent_id', $parentId);
         }
     }
     // make sure unique key won't cause trouble
     if ($transaction->isFailsafe()) {
         $autoincrementId = (int) $this->_lookupByTxnId($orderId, $paymentId, $txnId, $idFieldName);
         if ($autoincrementId) {
             $transaction->setData($idFieldName, $autoincrementId)->isObjectNew(false);
         }
     }
     return parent::_beforeSave($transaction);
 }
Ejemplo n.º 12
0
 /**
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order $object */
     $this->addressHandler->process($object);
     if (null !== $object->getItems()) {
         /** @var \Magento\Sales\Model\Order\Item $item */
         foreach ($object->getItems() as $item) {
             $item->setOrderId($object->getId());
             $item->setOrder($object);
             $item->save();
         }
     }
     if (null !== $object->getPayments()) {
         /** @var \Magento\Sales\Model\Order\Payment $payment */
         foreach ($object->getPayments() as $payment) {
             $payment->setParentId($object->getId());
             $payment->setOrder($object);
             $payment->save();
         }
     }
     if (null !== $object->getStatusHistories()) {
         /** @var \Magento\Sales\Model\Order\Status\History $statusHistory */
         foreach ($object->getStatusHistories() as $statusHistory) {
             $statusHistory->setParentId($object->getId());
             $statusHistory->save();
             $statusHistory->setOrder($object);
         }
     }
     foreach ($object->getRelatedObjects() as $relatedObject) {
         $relatedObject->save();
         $relatedObject->setOrder($object);
     }
     return parent::_afterSave($object);
 }
Ejemplo n.º 13
0
 /**
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\Order $object */
     $this->addressHandler->process($object);
     if (null !== $object->getItemsCollection()) {
         $object->getItemsCollection()->save();
     }
     if (null !== $object->getPaymentsCollection()) {
         $object->getPaymentsCollection()->save();
     }
     if (null !== $object->getStatusHistoryCollection()) {
         $object->getStatusHistoryCollection()->save();
     }
     foreach ($object->getRelatedObjects() as $relatedObject) {
         $relatedObject->save();
     }
     return parent::_afterSave($object);
 }