Selection.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Bundle\Model;
  7. /**
  8. * Bundle Selection Model
  9. *
  10. * @method int getSelectionId()
  11. * @method \Magento\Bundle\Model\Selection setSelectionId(int $value)
  12. * @method int getOptionId()
  13. * @method \Magento\Bundle\Model\Selection setOptionId(int $value)
  14. * @method int getParentProductId()
  15. * @method \Magento\Bundle\Model\Selection setParentProductId(int $value)
  16. * @method int getProductId()
  17. * @method \Magento\Bundle\Model\Selection setProductId(int $value)
  18. * @method int getPosition()
  19. * @method \Magento\Bundle\Model\Selection setPosition(int $value)
  20. * @method int getIsDefault()
  21. * @method \Magento\Bundle\Model\Selection setIsDefault(int $value)
  22. * @method int getSelectionPriceType()
  23. * @method \Magento\Bundle\Model\Selection setSelectionPriceType(int $value)
  24. * @method float getSelectionPriceValue()
  25. * @method \Magento\Bundle\Model\Selection setSelectionPriceValue(float $value)
  26. * @method float getSelectionQty()
  27. * @method \Magento\Bundle\Model\Selection setSelectionQty(float $value)
  28. * @method int getSelectionCanChangeQty()
  29. * @method \Magento\Bundle\Model\Selection setSelectionCanChangeQty(int $value)
  30. * @api
  31. * @since 100.0.2
  32. */
  33. class Selection extends \Magento\Framework\Model\AbstractModel
  34. {
  35. /**
  36. * Catalog data
  37. *
  38. * @var \Magento\Catalog\Helper\Data
  39. */
  40. protected $_catalogData;
  41. /**
  42. * @param \Magento\Framework\Model\Context $context
  43. * @param \Magento\Framework\Registry $registry
  44. * @param \Magento\Catalog\Helper\Data $catalogData
  45. * @param \Magento\Bundle\Model\ResourceModel\Selection $resource
  46. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  47. * @param array $data
  48. */
  49. public function __construct(
  50. \Magento\Framework\Model\Context $context,
  51. \Magento\Framework\Registry $registry,
  52. \Magento\Catalog\Helper\Data $catalogData,
  53. \Magento\Bundle\Model\ResourceModel\Selection $resource,
  54. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  55. array $data = []
  56. ) {
  57. $this->_catalogData = $catalogData;
  58. parent::__construct($context, $registry, $resource, $resourceCollection, $data);
  59. }
  60. /**
  61. * Initialize resource model
  62. *
  63. * @return void
  64. */
  65. protected function _construct()
  66. {
  67. $this->_init(\Magento\Bundle\Model\ResourceModel\Selection::class);
  68. parent::_construct();
  69. }
  70. /**
  71. * Processing object before save data
  72. *
  73. * @return $this
  74. */
  75. public function afterSave()
  76. {
  77. if (!$this->_catalogData->isPriceGlobal() && $this->getWebsiteId()) {
  78. $this->getResource()->saveSelectionPrice($this);
  79. if (!$this->getDefaultPriceScope()) {
  80. $this->unsSelectionPriceValue();
  81. $this->unsSelectionPriceType();
  82. }
  83. }
  84. parent::afterSave();
  85. }
  86. }