Factory.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Pricing\Price;
  7. use Magento\Framework\Pricing\SaleableInterface;
  8. /**
  9. * Price factory
  10. */
  11. class Factory
  12. {
  13. /**
  14. * Object Manager
  15. *
  16. * @var \Magento\Framework\ObjectManagerInterface
  17. */
  18. protected $objectManager;
  19. /**
  20. * Construct
  21. *
  22. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  23. */
  24. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  25. {
  26. $this->objectManager = $objectManager;
  27. }
  28. /**
  29. * Create Price object for particular product
  30. *
  31. * @param SaleableInterface $saleableItem
  32. * @param string $className
  33. * @param float $quantity
  34. * @param array $arguments
  35. * @throws \InvalidArgumentException
  36. * @return \Magento\Framework\Pricing\Price\PriceInterface
  37. */
  38. public function create(SaleableInterface $saleableItem, $className, $quantity, array $arguments = [])
  39. {
  40. $arguments['saleableItem'] = $saleableItem;
  41. $arguments['quantity'] = $quantity;
  42. $price = $this->objectManager->create($className, $arguments);
  43. if (!$price instanceof PriceInterface) {
  44. throw new \InvalidArgumentException(
  45. $className . ' doesn\'t implement \Magento\Framework\Pricing\Price\PriceInterface'
  46. );
  47. }
  48. return $price;
  49. }
  50. }