本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::setParentId方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::setParentId方法的具体用法?PHP AbstractModel::setParentId怎么用?PHP AbstractModel::setParentId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::setParentId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _beforeSave
/**
* @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);
}
示例2: _beforeSave
/**
* Perform actions before object save
*
* @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\DataObject $object
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
/** @var \Magento\Sales\Model\Order\Invoice\Item $object */
if (!$object->getParentId() && $object->getInvoice()) {
$object->setParentId($object->getInvoice()->getId());
}
return parent::_beforeSave($object);
}
示例3: _beforeSave
/**
* 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 \Magento\Sales\Model\Order\Shipment\Comment $object */
if (!$object->getParentId() && $object->getShipment()) {
$object->setParentId($object->getShipment()->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;
}