Swatch.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Swatches\Model\ResourceModel;
  7. /**
  8. * Swatch Resource Model
  9. *
  10. * @codeCoverageIgnore
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Swatch extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  15. {
  16. /**
  17. * Initialize resource model
  18. *
  19. * @return void
  20. */
  21. protected function _construct()
  22. {
  23. $this->_init('eav_attribute_option_swatch', 'swatch_id');
  24. }
  25. /**
  26. * Update default swatch option value.
  27. *
  28. * @param integer $id
  29. * @param string $defaultValue
  30. * @return void
  31. */
  32. public function saveDefaultSwatchOption($id, $defaultValue)
  33. {
  34. if ($defaultValue !== null) {
  35. $bind = ['default_value' => $defaultValue];
  36. $where = ['attribute_id = ?' => $id];
  37. $this->getConnection()->update($this->getTable('eav_attribute'), $bind, $where);
  38. }
  39. }
  40. /**
  41. * Cleaned swatch option values when switching to dropdown input type.
  42. *
  43. * @param array $optionIDs
  44. * @param int $type
  45. * @throws \Magento\Framework\Exception\LocalizedException
  46. * @since 100.2.4
  47. */
  48. public function clearSwatchOptionByOptionIdAndType($optionIDs, $type = null)
  49. {
  50. if (count($optionIDs)) {
  51. foreach ($optionIDs as $optionId) {
  52. $where = ['option_id = ?' => $optionId];
  53. if ($type !== null) {
  54. $where['type = ?'] = $type;
  55. }
  56. $this->getConnection()->delete($this->getMainTable(), $where);
  57. }
  58. }
  59. }
  60. }