Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RelationsDataSaver.php
Go to the documentation of this file.
1 <?php
7 
10 
17 {
21  private $resource;
22 
26  private $productRelation;
27 
32  public function __construct(
33  \Magento\Framework\App\ResourceConnection $resource,
34  Relation $productRelation = null
35  ) {
36  $this->resource = $resource;
37  $this->productRelation = $productRelation
38  ?: ObjectManager::getInstance()->get(Relation::class);
39  }
40 
48  public function saveOptions(array $options)
49  {
50  if (!empty($options)) {
51  $this->resource->getConnection()->insertOnDuplicate(
52  $this->resource->getTableName('catalog_product_bundle_option'),
53  $options,
54  [
55  'required',
56  'position',
57  'type'
58  ]
59  );
60  }
61  }
62 
70  public function saveOptionValues(array $optionValues)
71  {
72  if (!empty($optionValues)) {
73  $this->resource->getConnection()->insertOnDuplicate(
74  $this->resource->getTableName('catalog_product_bundle_option_value'),
75  $optionValues,
76  ['title']
77  );
78  }
79  }
80 
88  public function saveSelections(array $selections)
89  {
90  if (!empty($selections)) {
91  $this->resource->getConnection()->insertOnDuplicate(
92  $this->resource->getTableName('catalog_product_bundle_selection'),
93  $selections,
94  [
95  'selection_id',
96  'product_id',
97  'position',
98  'is_default',
99  'selection_price_type',
100  'selection_price_value',
101  'selection_qty',
102  'selection_can_change_qty'
103  ]
104  );
105  }
106  }
107 
116  public function saveProductRelations($parentId, $childIds)
117  {
118  $this->productRelation->processRelations($parentId, $childIds);
119  }
120 }
__construct(\Magento\Framework\App\ResourceConnection $resource, Relation $productRelation=null)
$resource
Definition: bulk.php:12