BundleSelectionFactory.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Bundle\Pricing\Price;
  7. use Magento\Catalog\Model\Product;
  8. /**
  9. * Bundle selection price factory
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class BundleSelectionFactory
  14. {
  15. /**
  16. * Default selection class
  17. */
  18. const SELECTION_CLASS_DEFAULT = \Magento\Bundle\Pricing\Price\BundleSelectionPrice::class;
  19. /**
  20. * Object Manager
  21. *
  22. * @var \Magento\Framework\ObjectManagerInterface
  23. */
  24. protected $objectManager;
  25. /**
  26. * Construct
  27. *
  28. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  29. */
  30. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  31. {
  32. $this->objectManager = $objectManager;
  33. }
  34. /**
  35. * Create Price object for particular product
  36. *
  37. * @param Product $bundleProduct
  38. * @param Product $selection
  39. * @param float $quantity
  40. * @param array $arguments
  41. * @return BundleSelectionPrice
  42. */
  43. public function create(
  44. Product $bundleProduct,
  45. Product $selection,
  46. $quantity,
  47. array $arguments = []
  48. ) {
  49. $arguments['bundleProduct'] = $bundleProduct;
  50. $arguments['saleableItem'] = $selection;
  51. $arguments['quantity'] = $quantity ? (float)$quantity : 1.;
  52. return $this->objectManager->create(self::SELECTION_CLASS_DEFAULT, $arguments);
  53. }
  54. }