15 class Table extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
37 private $storeManager;
48 $this->_attrOptionCollectionFactory = $attrOptionCollectionFactory;
49 $this->_attrOptionFactory = $attrOptionFactory;
59 public function getAllOptions($withEmpty =
true, $defaultValues =
false)
63 $storeId = $this->getStoreManager()->getStore()->getId();
65 if (!is_array($this->_options)) {
68 if (!is_array($this->_optionsDefault)) {
69 $this->_optionsDefault = [];
72 if (!isset($this->_options[
$storeId][$attributeId])) {
73 $collection = $this->_attrOptionCollectionFactory->create()->setPositionOrder(
75 )->setAttributeFilter(
81 $this->_optionsDefault[
$storeId][$attributeId] =
$collection->toOptionArray(
'default_value');
84 ? $this->_optionsDefault[
$storeId][$attributeId]
85 : $this->_options[
$storeId][$attributeId];
99 private function getStoreManager()
101 if ($this->storeManager ===
null) {
104 return $this->storeManager;
116 $options = $this->_attrOptionCollectionFactory->create()
117 ->setPositionOrder(
'asc')
119 ->addFieldToFilter(
'main_table.option_id', [
'in' => $ids])
133 private function addEmptyOption(array
$options)
148 if (strpos(
$value,
',') !==
false) {
167 return $item[
'label'];
184 $valueTable1 =
$attribute->getAttributeCode() .
'_t1';
185 $valueTable2 =
$attribute->getAttributeCode() .
'_t2';
186 $linkField =
$attribute->getEntity()->getLinkField();
188 [$valueTable1 =>
$attribute->getBackend()->getTable()],
189 "e.{$linkField}={$valueTable1}." . $linkField .
190 " AND {$valueTable1}.attribute_id='{$attribute->getId()}'" .
191 " AND {$valueTable1}.store_id=0",
194 [$valueTable2 =>
$attribute->getBackend()->getTable()],
195 "e.{$linkField}={$valueTable2}." . $linkField .
196 " AND {$valueTable2}.attribute_id='{$attribute->getId()}'" .
197 " AND {$valueTable2}.store_id='{$collection->getStoreId()}'",
200 $valueExpr =
$collection->getSelect()->getConnection()->getCheckSql(
201 "{$valueTable2}.value_id > 0",
202 "{$valueTable2}.value",
203 "{$valueTable1}.value" 206 $this->_attrOptionFactory->create()->addOptionValueToCollection(
212 $collection->getSelect()->order(
"{$attribute->getAttributeCode()} {$dir}");
226 $isMulti = $this->
getAttribute()->getFrontend()->getInputType() ==
'multiselect';
231 'length' => $isMulti ?
'255' :
null,
263 $indexes[
$index] = [
'type' =>
'index',
'fields' => [$this->
getAttribute()->getAttributeCode()]];
271 'fields' => [$this->
getAttribute()->getAttributeCode() .
'_value'],
286 return $this->_attrOptionFactory->create()->getFlatUpdateSelect($this->
getAttribute(),
$store);
__construct(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory)
getSpecificOptions($ids, $withEmpty=true)
getAllOptions($withEmpty=true, $defaultValues=false)
addValueSortToCollection($collection, $dir=\Magento\Framework\DB\Select::SQL_ASC)
getFlatUpdateSelect($store)
$_attrOptionCollectionFactory