Skip to content

Commit

Permalink
Merge pull request #106 from magento-fearless-kiwis/develop
Browse files Browse the repository at this point in the history
[Kiwis] Bug Fixes
  • Loading branch information
sdwright authored Jun 15, 2016
2 parents 982e52c + 8cb6668 commit 2ddfe0f
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 5 deletions.
65 changes: 63 additions & 2 deletions app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Eav\Model\Config;
use Magento\Framework\App\RequestInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Ui\DataProvider\EavValidationRules;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\Collection as GroupCollection;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory as GroupCollectionFactory;
Expand All @@ -28,6 +29,9 @@
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Eav\Api\Data\AttributeGroupInterface;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Framework\Currency;
use Magento\Framework\Locale\Currency as CurrencyLocale;
Use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

/**
* Class EavTest
Expand Down Expand Up @@ -138,9 +142,35 @@ class EavTest extends AbstractModifierTest
*/
private $eavAttributeMock;

/**
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $storeMock;

/**
* @var Currency|\PHPUnit_Framework_MockObject_MockObject
*/
protected $currencyMock;

/**
* @var CurrencyLocale|\PHPUnit_Framework_MockObject_MockObject
*/
protected $currencyLocaleMock;

/**
* @var ObjectManager
*/
protected $objectManager;

/**
* @var Eav
*/
protected $eav;

protected function setUp()
{
parent::setUp();
$this->objectManager = new ObjectManager($this);
$this->eavConfigMock = $this->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -236,6 +266,24 @@ protected function setUp()
->willReturn([
$this->attributeMock,
]);
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
->setMethods(['load', 'getId', 'getConfig', 'getBaseCurrencyCode'])
->getMockForAbstractClass();
$this->currencyMock = $this->getMockBuilder(Currency::class)
->disableOriginalConstructor()
->setMethods(['toCurrency'])
->getMock();
$this->currencyLocaleMock = $this->getMockBuilder(CurrencyLocale::class)
->disableOriginalConstructor()
->setMethods(['getCurrency'])
->getMock();

$this->eav =$this->getModel();
$this->objectManager->setBackwardCompatibleProperty(
$this->eav,
'localeCurrency',
$this->currencyLocaleMock
);
}

/**
Expand All @@ -255,7 +303,7 @@ protected function createModel()
'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock,
'attributeGroupRepository' => $this->attributeGroupRepositoryMock,
'sortOrderBuilder' => $this->sortOrderBuilderMock,
'attributeRepository' => $this->attributeRepositoryMock
'attributeRepository' => $this->attributeRepositoryMock,
]);
}

Expand Down Expand Up @@ -336,6 +384,19 @@ public function testModifyData()
->method('getItems')
->willReturn([$this->eavAttributeMock]);

$this->assertEquals($sourceData, $this->getModel()->modifyData([]));
$this->storeMock->expects(($this->once()))
->method('getBaseCurrencyCode')
->willReturn('en_US');
$this->storeManagerMock->expects($this->once())
->method('getStore')
->willReturn($this->storeMock);
$this->currencyMock->expects($this->once())
->method('toCurrency')
->willReturn('19.99');
$this->currencyLocaleMock->expects($this->once())
->method('getCurrency')
->willReturn($this->currencyMock);

$this->assertEquals($sourceData, $this->eav->modifyData([]));
}
}
42 changes: 41 additions & 1 deletion app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magento\Ui\Component\Form\Element\ActionDelete;
use Magento\Ui\Component\Form\Element\DataType\Text;
use Magento\Ui\Component\Form\Element\DataType\Number;
use Magento\Framework\Locale\CurrencyInterface;

/**
* Data provider for "Customizable Options" panel
Expand Down Expand Up @@ -111,7 +112,7 @@ class CustomOptions extends AbstractModifier
* @var UrlInterface
*/
protected $urlBuilder;

/**
* @var ArrayManager
*/
Expand All @@ -122,6 +123,11 @@ class CustomOptions extends AbstractModifier
*/
protected $meta = [];

/**
* @var CurrencyInterface
*/
private $localeCurrency;

/**
* @param LocatorInterface $locator
* @param StoreManagerInterface $storeManager
Expand Down Expand Up @@ -1069,4 +1075,38 @@ protected function getCurrencySymbol()
{
return $this->storeManager->getStore()->getBaseCurrency()->getCurrencySymbol();
}

/**
* The getter function to get the locale currency for real application code
*
* @return \Magento\Framework\Locale\CurrencyInterface
*
* @deprecated
*/
private function getLocaleCurrency()
{
if ($this->localeCurrency === null) {
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
}
return $this->localeCurrency;
}

/**
* Format price according to the locale of the currency
*
* @param mixed $value
* @return string
*/
protected function formatPrice($value)
{
if (!is_numeric($value)) {
return null;
}

$store = $this->storeManager->getStore();
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);

return $value;
}
}
40 changes: 40 additions & 0 deletions app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Magento\Ui\DataProvider\Mapper\MetaProperties as MetaPropertiesMapper;
use Magento\Ui\Component\Form\Element\Wysiwyg as WysiwygElement;
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
use Magento\Framework\Locale\CurrencyInterface;

/**
* Class Eav
Expand Down Expand Up @@ -161,6 +162,11 @@ class Eav extends AbstractModifier
*/
private $prevSetAttributes;

/**
* @var CurrencyInterface
*/
private $localeCurrency;

/**
* @param LocatorInterface $locator
* @param CatalogEavValidationRules $catalogEavValidationRules
Expand Down Expand Up @@ -867,4 +873,38 @@ private function calculateGroupCode(AttributeGroupInterface $group)

return $attributeGroupCode;
}

/**
* The getter function to get the locale currency for real application code
*
* @return \Magento\Framework\Locale\CurrencyInterface
*
* @deprecated
*/
private function getLocaleCurrency()
{
if ($this->localeCurrency === null) {
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
}
return $this->localeCurrency;
}

/**
* Format price according to the locale of the currency
*
* @param mixed $value
* @return string
*/
protected function formatPrice($value)
{
if (!is_numeric($value)) {
return null;
}

$store = $this->storeManager->getStore();
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);

return $value;
}
}
89 changes: 87 additions & 2 deletions app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Ui\Component\Form;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Locale\CurrencyInterface;

/**
* Data provider for main panel of product page
Expand All @@ -24,6 +26,16 @@ class General extends AbstractModifier
* @var ArrayManager
*/
protected $arrayManager;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var CurrencyInterface
*/
private $localeCurrency;

/**
* @param LocatorInterface $locator
Expand Down Expand Up @@ -70,7 +82,7 @@ protected function customizeWeightFormat(array $data)
$data = $this->arrayManager->replace(
$path,
$data,
$this->formatWeight($this->arrayManager->get($path, $data))
$this->formatNumber($this->arrayManager->get($path, $data))
);
}

Expand All @@ -93,7 +105,7 @@ protected function customizeAdvancedPriceFormat(array $data)
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE] =
$this->formatPrice($value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE]);
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY] =
(int)$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY];
$this->formatNumber((int)$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY]);
}
}

Expand Down Expand Up @@ -350,4 +362,77 @@ protected function customizeNameListeners(array $meta)
]
);
}

/**
* The getter function to get the locale currency for real application code
*
* @return \Magento\Framework\Locale\CurrencyInterface
*
* @deprecated
*/
private function getLocaleCurrency()
{
if ($this->localeCurrency === null) {
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
}
return $this->localeCurrency;
}

/**
* The getter function to get the store manager for real application code
*
* @return \Magento\Store\Model\StoreManagerInterface
*
* @deprecated
*/
private function getStoreManager()
{
if ($this->storeManager === null) {
$this->storeManager =
\Magento\Framework\App\ObjectManager::getInstance()->get(StoreManagerInterface::class);
}
return $this->storeManager;
}


/**
* Format price according to the locale of the currency
*
* @param mixed $value
* @return string
*/
protected function formatPrice($value)
{
if (!is_numeric($value)) {
return null;
}

$store = $this->getStoreManager()->getStore();
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);

return $value;
}

/**
* Format number according to the locale of the currency and precision of input
*
* @param mixed $value
* @return string
*/
protected function formatNumber($value)
{
if (!is_numeric($value)) {
return null;
}

$value = (float)$value;
$precision = strlen(substr(strrchr($value, "."), 1));
$store = $this->getStoreManager()->getStore();
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL,
'precision' => $precision]);

return $value;
}
}
3 changes: 3 additions & 0 deletions lib/internal/Magento/Framework/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ public function getCollection()
* @param integer $modelId
* @param null|string $field
* @return $this
* @deprecated
*/
public function load($modelId, $field = null)
{
Expand Down Expand Up @@ -623,6 +624,7 @@ public function setHasDataChanges($flag)
*
* @return $this
* @throws \Exception
* @deprecated
*/
public function save()
{
Expand Down Expand Up @@ -807,6 +809,7 @@ public function afterSave()
*
* @return $this
* @throws \Exception
* @deprecated
*/
public function delete()
{
Expand Down

0 comments on commit 2ddfe0f

Please sign in to comment.