/** * Returns percent discount * * @return bool|float */ public function getDiscountPercent() { if ($this->percent === null) { $percent = parent::getValue(); $this->percent = $percent ? max(0, min(100, 100 - $percent)) : null; } return $this->percent; }
/** * Test getter stored tier prices from eav model * * @covers \Magento\Catalog\Pricing\Price\TierPrice::__construct * @covers \Magento\Catalog\Pricing\Price\TierPrice::getStoredTierPrices */ public function testGetterStoredTierPrices() { $this->product->expects($this->once())->method('hasCustomerGroupId')->will($this->returnValue(true)); $this->product->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($this->customerGroup)); $backendMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', [], [], '', false); $attributeMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], [], '', false); $attributeMock->expects($this->once())->method('getBackend')->will($this->returnValue($backendMock)); $productResource = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product', [], [], '', false); $productResource->expects($this->once())->method('getAttribute')->with(TierPrice::PRICE_CODE)->will($this->returnValue($attributeMock)); $this->product->expects($this->once())->method('getResource')->will($this->returnValue($productResource)); $tierPrice = new TierPrice($this->product, $this->quantity, $this->calculator, $this->priceCurrencyMock, $this->session, $this->groupManagement); $group = $this->getMock('\\Magento\\Customer\\Model\\Data\\Group', [], [], '', false); $group->expects($this->once())->method('getId')->willReturn(GroupManagement::CUST_GROUP_ALL); $this->groupManagement->expects($this->once())->method('getAllCustomersGroup')->will($this->returnValue($group)); $this->assertFalse($tierPrice->getValue()); }
/** * Test getter stored tier prices from eav model * * @covers \Magento\Catalog\Pricing\Price\TierPrice::__construct * @covers \Magento\Catalog\Pricing\Price\TierPrice::getStoredTierPrices */ public function testGetterStoredTierPrices() { $this->product->expects($this->once())->method('hasCustomerGroupId')->will($this->returnValue(true)); $this->product->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue($this->customerGroup)); $backendMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', [], [], '', false); $attributeMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], [], '', false); $attributeMock->expects($this->once())->method('getBackend')->will($this->returnValue($backendMock)); $productResource = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product', [], [], '', false); $productResource->expects($this->once())->method('getAttribute')->with(TierPrice::PRICE_CODE)->will($this->returnValue($attributeMock)); $this->product->expects($this->once())->method('getResource')->will($this->returnValue($productResource)); $tierPrice = new TierPrice($this->product, $this->quantity, $this->calculator, $this->session); $this->assertFalse($tierPrice->getValue()); }