Msrp.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Msrp\Model;
  7. use Magento\Catalog\Model\Product;
  8. use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory;
  9. class Msrp
  10. {
  11. /**
  12. * @var array
  13. */
  14. protected $mapApplyToProductType = null;
  15. /**
  16. * @var AttributeFactory
  17. */
  18. protected $eavAttributeFactory;
  19. /**
  20. * @param AttributeFactory $eavAttributeFactory
  21. */
  22. public function __construct(
  23. AttributeFactory $eavAttributeFactory
  24. ) {
  25. $this->eavAttributeFactory = $eavAttributeFactory;
  26. }
  27. /**
  28. * Check whether Msrp applied to product Product Type
  29. *
  30. * @param \Magento\Catalog\Model\Product $product
  31. * @return bool
  32. * @api
  33. */
  34. public function canApplyToProduct($product)
  35. {
  36. if ($this->mapApplyToProductType === null) {
  37. /** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
  38. $attribute = $this->eavAttributeFactory->create()->loadByCode(Product::ENTITY, 'msrp');
  39. $this->mapApplyToProductType = $attribute->getApplyTo();
  40. }
  41. return in_array($product->getTypeId(), $this->mapApplyToProductType);
  42. }
  43. }