Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Source.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Exception;
16 use Magento\Framework\Model\ResourceModel\PredefinedId;
17 
21 class Source extends AbstractDb
22 {
26  use PredefinedId;
27 
31  const TABLE_NAME_SOURCE = 'inventory_source';
39  protected $_isPkAutoIncrement = false;
40 
44  private $sourceCarrierLinkManagement;
45 
51  public function __construct(
52  Context $context,
53  SourceCarrierLinkManagementInterface $sourceCarrierLinkManagement,
54  $connectionName = null
55  ) {
56  parent::__construct($context, $connectionName);
57  $this->sourceCarrierLinkManagement = $sourceCarrierLinkManagement;
58  }
59 
63  protected function _construct()
64  {
65  $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::SOURCE_CODE);
66  }
67 
71  public function load(AbstractModel $object, $value, $field = null)
72  {
73  parent::load($object, $value, $field);
75  $this->sourceCarrierLinkManagement->loadCarrierLinksBySource($object);
76  return $this;
77  }
78 
82  public function save(AbstractModel $object)
83  {
84  $connection = $this->getConnection();
85  $connection->beginTransaction();
86  try {
87  parent::save($object);
89  $this->sourceCarrierLinkManagement->saveCarrierLinksBySource($object);
90  $connection->commit();
91  } catch (Exception $e) {
92  $connection->rollBack();
93  throw $e;
94  }
95  return $this;
96  }
97 }
__construct(Context $context, SourceCarrierLinkManagementInterface $sourceCarrierLinkManagement, $connectionName=null)
Definition: Source.php:51
save(\Magento\Framework\Model\AbstractModel $object)
Definition: AbstractDb.php:391
$value
Definition: gender.phtml:16
load(\Magento\Framework\Model\AbstractModel $object, $value, $field=null)
Definition: AbstractDb.php:339
$connection
Definition: bulk.php:13