Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateAdminTextSwatchValues.php
Go to the documentation of this file.
1 <?php
8 
11 use Zend_Db;
12 use Zend_Db_Expr;
16 
22 {
26  private $moduleDataSetup;
27 
32  public function __construct(
33  \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
34  ) {
35  $this->moduleDataSetup = $moduleDataSetup;
36  }
37 
41  public function apply()
42  {
43  $this->moduleDataSetup->getConnection()->startSetup();
44  $this->updateAdminTextSwatchValues();
45  $this->moduleDataSetup->getConnection()->endSetup();
46  }
47 
51  public static function getDependencies()
52  {
53  return [
54  AddSwatchImageToDefaultAttribtueSet::class
55  ];
56  }
57 
61  public static function getVersion()
62  {
63  return '2.0.2';
64  }
65 
69  public function getAliases()
70  {
71  return [];
72  }
73 
77  private function updateAdminTextSwatchValues()
78  {
79  $connection = $this->moduleDataSetup->getConnection();
80  $storeData = $connection
81  ->select()
82  ->from($this->moduleDataSetup->getTable('store'))
83  ->where(Store::STORE_ID . "<> ? ", Store::DEFAULT_STORE_ID)
84  ->order("sort_order desc")
85  ->limit(1)
86  ->query(Zend_Db::FETCH_ASSOC)
87  ->fetch();
88 
89  if (is_array($storeData)) {
90 
102  ->select()
103  ->joinLeft(
104  ["ls" => $this->moduleDataSetup->getTable('eav_attribute_option_swatch')],
105  new Zend_Db_Expr("ls.option_id = s.option_id AND ls.store_id = " . $storeData[Store::STORE_ID]),
106  ["value"]
107  )
108  ->where("s.store_id = ? ", Store::DEFAULT_STORE_ID)
109  ->where("s.type = ? ", Swatch::SWATCH_TYPE_TEXTUAL)
110  ->where("s.value = ? or s.value is null", "");
111 
112  $connection->query(
113  $connection->updateFromSelect(
114  $select,
115  ["s" => $this->moduleDataSetup->getTable('eav_attribute_option_swatch')]
116  )
117  );
118  }
119  }
120 }
const FETCH_ASSOC
Definition: Db.php:142
$connection
Definition: bulk.php:13
__construct(\Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup)