Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ProductPriceUtils.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Lc\ShopBundle\Services\Price;
  3. use Doctrine\Common\Collections\Collection;
  4. use Lc\ShopBundle\Context\OrderProductInterface;
  5. use Lc\ShopBundle\Context\OrderShopInterface;
  6. use Lc\ShopBundle\Context\ProductFamilyInterface;
  7. use Lc\ShopBundle\Context\ProductInterface;
  8. use Lc\ShopBundle\Context\ProductPropertyInterface;
  9. use Lc\ShopBundle\Context\ReductionCatalogInterface;
  10. class ProductPriceUtils
  11. {
  12. use PriceUtilsTrait ;
  13. public function getPrice(ProductPropertyInterface $product)
  14. {
  15. if ($product->getBehaviorPriceInherited() == 'by-piece') {
  16. return $product->getPriceInherited();
  17. }
  18. elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
  19. if ($product->getQuantityInherited() > 0) {
  20. return $product->getPriceByRefUnitInherited() * ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient());
  21. }
  22. }
  23. }
  24. public function getPriceWithTax(ProductPropertyInterface $product)
  25. {
  26. return $this->applyTax(
  27. $this->getPrice($product),
  28. $product->getTaxRateInherited()->getValue()
  29. );
  30. }
  31. public function getPriceByRefUnit(ProductPropertyInterface $product)
  32. {
  33. if ($product->getBehaviorPriceInherited() == 'by-piece') {
  34. return ($this->getPrice($product) * $product->getUnitInherited()->getCoefficient()) / $product->getQuantityInherited();
  35. } elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
  36. return $product->getPriceByRefUnitInherited();
  37. }
  38. }
  39. public function getPriceByRefUnitWithTax(ProductPropertyInterface $product)
  40. {
  41. return $this->applyTax(
  42. $this->getPriceByRefUnit($product),
  43. $product->getTaxRateInherited()->getValue()
  44. );
  45. }
  46. public function getPriceWithTaxAndReduction(ProductPropertyInterface $product)
  47. {
  48. return $this->applyReductionCatalog(
  49. $product,
  50. $this->getPrice($product),
  51. $this->getPriceWithTax($product)
  52. );
  53. }
  54. public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product)
  55. {
  56. return $this->applyReductionCatalog(
  57. $product,
  58. $this->getPriceByRefUnit($product),
  59. $this->getPriceByRefUnitWithTax($product)
  60. );
  61. }
  62. }