Skip to content
Snippets Groups Projects
Commit 78c1fa94 authored by Andy Summers's avatar Andy Summers
Browse files

Merge branch 'base-price-money' into 'master'

Use `Money` for Product base price instead of float

See merge request adi-ia/cbs-techstore-client-php!96
parents ed12b53f 9e064fcb
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@
"mockery/mockery": "^1.1.0",
"monolog/monolog": "^1.23.0",
"phing/phing": "^2.16.1",
"phpunit/phpunit": "^7.0",
"phpunit/phpunit": "^6.0",
"wsdl2phpgenerator/wsdl2phpgenerator": "3.4.0"
},
"autoload": {
......
This diff is collapsed.
......@@ -2,6 +2,7 @@
namespace edu\wisc\services\cbs\common;
use edu\wisc\services\cbs\exception\UnsupportedCurrencyException;
use Money\Currency;
use Money\Money;
/**
......@@ -21,6 +22,7 @@ class MoneyConversion
{
$costFloat = null;
if (null !== $money) {
/** @var Currency $currency */
$currency = $money->getCurrency()->getCode();
if ($currency !== 'USD') {
throw new UnsupportedCurrencyException("Unsupported currency: $currency");
......
......@@ -81,7 +81,7 @@ class Product
/** @var string UPC alternate (barcode) */
private $upcAlternate = '';
/** @var float base price */
/** @var Money base price */
private $basePrice;
/** @var string */
......@@ -537,18 +537,18 @@ class Product
}
/**
* @return float
* @return Money
*/
public function getBasePrice(): float
public function getBasePrice()
{
return $this->basePrice;
}
/**
* @param float $basePrice
* @param Money $basePrice
* @return Product
*/
public function setBasePrice(float $basePrice): Product
public function setBasePrice(Money $basePrice): Product
{
$this->basePrice = $basePrice;
return $this;
......
......@@ -3,7 +3,7 @@ namespace edu\wisc\services\cbs\product;
use edu\wisc\services\cbs\common\MoneyConversion;
use edu\wisc\services\cbs\exception\UnsupportedCurrencyException;
use edu\wisc\services\cbs\product\create\generated\InputParameters as CreateInputParamters;
use edu\wisc\services\cbs\product\create\generated\InputParameters as CreateInputParameters;
use edu\wisc\services\cbs\product\update\generated\InputParameters as UpdateInputParameters;
/**
......@@ -28,7 +28,7 @@ class ProductInputParametersMapper
{
$inputParameters = null;
if ($type === static::$CREATE) {
$inputParameters = new CreateInputParamters(
$inputParameters = new CreateInputParameters(
'', # P_ITEM_NUMBER
'', # P_ITEM_DESCRIPTION
'', # P_CBS_ITEM_TEMPLATE
......@@ -151,7 +151,7 @@ class ProductInputParametersMapper
->setP_SUPPLIER_PART_NUMBER($product->getVendorPartNumber())
->setP_UPC($product->getUpc())
->setP_UPC_ALTERNATE($product->getUpcAlternate())
->setP_BASE_PRICE($product->getBasePrice())
->setP_BASE_PRICE(MoneyConversion::convertMoneyToFloat($product->getBasePrice()))
->setP_PRICING_TEMPLATE($product->getPricingTemplate())
->setP_REFERENCE($product->getReference())
->setP_COST_CENTER($product->getCostCenter())
......
......@@ -23,7 +23,7 @@ class ProductInputParametersMapperTest extends TestCase
static::assertInstanceOf(\edu\wisc\services\cbs\product\create\generated\InputParameters::class, $inputParameters);
static::assertEquals($product->getAddSalesInstructions(), $inputParameters->getP_ADD_SALES_INSTRUCTIONS());
static::assertEquals($product->getBasePrice(), $inputParameters->getP_BASE_PRICE());
static::assertEquals(MoneyConversion::convertMoneyToFloat($product->getBasePrice()), $inputParameters->getP_BASE_PRICE());
static::assertEquals($product->getBuyer(), $inputParameters->getP_BUYER());
static::assertEquals($product->getCbsItemTemplate(), $inputParameters->getP_CBS_ITEM_TEMPLATE());
static::assertEquals(MoneyConversion::convertMoneyToFloat($product->getCost()), $inputParameters->getP_COST());
......@@ -83,7 +83,7 @@ class ProductInputParametersMapperTest extends TestCase
);
static::assertInstanceOf(\edu\wisc\services\cbs\product\update\generated\InputParameters::class, $inputParameters);
static::assertEquals($product->getAddSalesInstructions(), $inputParameters->getP_ADD_SALES_INSTRUCTIONS());
static::assertEquals($product->getBasePrice(), $inputParameters->getP_BASE_PRICE());
static::assertEquals(MoneyConversion::convertMoneyToFloat($product->getBasePrice()), $inputParameters->getP_BASE_PRICE());
static::assertEquals($product->getBuyer(), $inputParameters->getP_BUYER());
static::assertEquals($product->getCbsItemTemplate(), $inputParameters->getP_CBS_ITEM_TEMPLATE());
static::assertEquals(MoneyConversion::convertMoneyToFloat($product->getCost()), $inputParameters->getP_COST());
......@@ -154,7 +154,7 @@ class ProductInputParametersMapperTest extends TestCase
{
$product = (new Product())
->setAddSalesInstructions('Special sales instructions go here')
->setBasePrice(5.0)
->setBasePrice(Money::USD(50))
->setBuyer('APPLEBUYER')
->setCbsItemTemplate('Commodity')
->setCostCenter(5060)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment