Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Collection.php
Go to the documentation of this file.
1 <?php
7 
14 {
20  protected $_itemIds;
21 
27  protected $_selectionsAppended = false;
28 
34  protected function _construct()
35  {
36  $this->_init(\Magento\Bundle\Model\Option::class, \Magento\Bundle\Model\ResourceModel\Option::class);
37  }
38 
45  public function joinValues($storeId)
46  {
47  $this->getSelect()->joinLeft(
48  ['option_value_default' => $this->getTable('catalog_product_bundle_option_value')],
49  implode(
50  ' AND ',
51  [
52  'main_table.option_id = option_value_default.option_id',
53  'main_table.parent_id = option_value_default.parent_product_id',
54  'option_value_default.store_id = 0'
55  ]
56  ),
57  []
58  )->columns(
59  ['default_title' => 'option_value_default.title']
60  );
61 
62  $title = $this->getConnection()->getCheckSql(
63  'option_value.title IS NOT NULL',
64  'option_value.title',
65  'option_value_default.title'
66  );
67  if ($storeId !== null) {
68  $this->getSelect()->columns(
69  ['title' => $title]
70  )->joinLeft(
71  ['option_value' => $this->getTable('catalog_product_bundle_option_value')],
72  $this->getConnection()->quoteInto(
73  implode(
74  ' AND ',
75  [
76  'main_table.option_id = option_value.option_id',
77  'main_table.parent_id = option_value.parent_product_id',
78  'option_value.store_id = ?'
79  ]
80  ),
81  $storeId
82  ),
83  []
84  );
85  }
86  return $this;
87  }
88 
95  public function setProductIdFilter($productId)
96  {
97  $productTable = $this->getTable('catalog_product_entity');
98  $linkField = $this->getConnection()->getAutoIncrementField($productTable);
99  $this->getSelect()->join(
100  ['cpe' => $productTable],
101  'cpe.'.$linkField.' = main_table.parent_id',
102  []
103  )->where(
104  "cpe.entity_id = ?",
105  $productId
106  );
107 
108  return $this;
109  }
110 
119  public function setProductLinkFilter($productLinkFieldValue)
120  {
121  $this->getSelect()->where(
122  'main_table.parent_id = ?',
123  $productLinkFieldValue
124  );
125  return $this;
126  }
127 
133  public function setPositionOrder()
134  {
135  $this->getSelect()->order('main_table.position asc')->order('main_table.option_id asc');
136  return $this;
137  }
138 
149  public function appendSelections($selectionsCollection, $stripBefore = false, $appendAll = true)
150  {
151  if ($stripBefore) {
152  $this->_stripSelections();
153  }
154 
155  if (!$this->_selectionsAppended) {
156  foreach ($selectionsCollection->getItems() as $key => $selection) {
157  $option = $this->getItemById($selection->getOptionId());
158  if ($option) {
159  if ($appendAll || $selection->isSalable() && !$selection->getRequiredOptions()) {
160  $selection->setOption($option);
161  $option->addSelection($selection);
162  } else {
163  $selectionsCollection->removeItemByKey($key);
164  }
165  }
166  }
167  $this->_selectionsAppended = true;
168  }
169 
170  return $this->getItems();
171  }
172 
178  protected function _stripSelections()
179  {
180  foreach ($this->getItems() as $option) {
181  $option->setSelections([]);
182  }
183  $this->_selectionsAppended = false;
184  return $this;
185  }
186 
193  public function setIdFilter($ids)
194  {
195  if (is_array($ids)) {
196  $this->addFieldToFilter('main_table.option_id', ['in' => $ids]);
197  } elseif ($ids != '') {
198  $this->addFieldToFilter('main_table.option_id', $ids);
199  }
200  return $this;
201  }
202 
208  public function resetAllIds()
209  {
210  $this->_itemIds = null;
211  return $this;
212  }
213 
219  public function getAllIds()
220  {
221  if ($this->_itemIds === null) {
222  $this->_itemIds = parent::getAllIds();
223  }
224  return $this->_itemIds;
225  }
226 }
$title
Definition: default.phtml:14
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
appendSelections($selectionsCollection, $stripBefore=false, $appendAll=true)
Definition: Collection.php:149