Skip to content

Commit

Permalink
Merge pull request #269 from magento-api/MAGETWO-45161-RPC
Browse files Browse the repository at this point in the history
[API] API Out: RPC Integration. Part 1
  • Loading branch information
Korshenko, Olexii(okorshenko) committed Jan 4, 2016
2 parents c58d2da + 8e7425e commit cebf7e3
Show file tree
Hide file tree
Showing 72 changed files with 2,896 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,25 @@ class CountrycreditcardTest extends \PHPUnit_Framework_TestCase
*/
protected $objectManagerHelper;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $resourceMock;

/**
* @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject
*/
protected $mathRandomMock;

protected function setUp()
{
$this->resourceMock = $this->getMockForAbstractClass('\Magento\Framework\Model\ResourceModel\AbstractResource');
$this->objectManagerHelper = new ObjectManagerHelper($this);

$this->mathRandomMock = $this->getMockBuilder(
'\Magento\Framework\Math\Random'
)->disableOriginalConstructor()
->getMock();

$this->objectManagerHelper = new ObjectManagerHelper($this);

$this->model = $this->objectManagerHelper->getObject(
'\Magento\Braintree\Model\System\Config\Backend\Countrycreditcard',
[
'mathRandom' => $this->mathRandomMock,
'resource' => $this->resourceMock,
'mathRandom' => $this->mathRandomMock
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Controller/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function execute()

// Render page
try {
$page = $this->resultPageFactory->create(false, ['isIsolated' => true]);
$page = $this->resultPageFactory->create();
$this->viewHelper->prepareAndRender($page, $productId, $this, $params);
return $page;
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
Expand Down
26 changes: 20 additions & 6 deletions app/code/Magento/Catalog/Helper/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ public function initProductLayout(ResultPage $resultPage, $product, $params = nu
*/
public function prepareAndRender(ResultPage $resultPage, $productId, $controller, $params = null)
{
/**
* Remove default action handle from layout update to avoid its usage during processing of another action,
* It is possible that forwarding to another action occurs, e.g. to 'noroute'.
* Default action handle is restored just before the end of current method.
*/
$defaultActionHandle = $resultPage->getDefaultLayoutHandle();
$handles = $resultPage->getLayout()->getUpdate()->getHandles();
if (in_array($defaultActionHandle, $handles)) {
$resultPage->getLayout()->getUpdate()->removeHandle($resultPage->getDefaultLayoutHandle());
}

if (!$controller instanceof \Magento\Catalog\Controller\Product\View\ViewInterface) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Bad controller interface for showing product')
);
}
// Prepare data
$productHelper = $this->_catalogProduct;
if (!$params) {
Expand All @@ -211,13 +227,11 @@ public function prepareAndRender(ResultPage $resultPage, $productId, $controller

$this->_catalogSession->setLastViewedProductId($product->getId());

$this->initProductLayout($resultPage, $product, $params);

if (!$controller instanceof \Magento\Catalog\Controller\Product\View\ViewInterface) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Bad controller interface for showing product')
);
if (in_array($defaultActionHandle, $handles)) {
$resultPage->addDefaultHandle();
}

$this->initProductLayout($resultPage, $product, $params);
return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
data-validate="{required:true, 'validate-email':true}"
id="customer-email" />
<!-- ko template: 'ui/form/element/helper/tooltip' --><!-- /ko -->
<span class="note" data-bind="fadeVisible: isPasswordVisible() == false"><!-- ko i18n: "You can create an account after checkout."--><!-- /ko --></span>
<span class="note" data-bind="fadeVisible: isPasswordVisible() == false"><!-- ko i18n: 'You can create an account after checkout.'--><!-- /ko --></span>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
protected $helperData;

/**
* @var string[]
*/
protected $countriesWithNotRequiredStates;

/**
* Initialize dependencies.
*
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
Expand All @@ -64,6 +71,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
* @param \Magento\Framework\App\Helper\AbstractHelper $helperData
* @param array $countriesWithNotRequiredStates
* @param mixed $connection
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand All @@ -79,6 +87,7 @@ public function __construct(
\Magento\Framework\Stdlib\ArrayUtils $arrayUtils,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Framework\App\Helper\AbstractHelper $helperData,
array $countriesWithNotRequiredStates = [],
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
) {
Expand All @@ -89,6 +98,7 @@ public function __construct(
$this->_countryFactory = $countryFactory;
$this->_arrayUtils = $arrayUtils;
$this->helperData = $helperData;
$this->countriesWithNotRequiredStates = $countriesWithNotRequiredStates;
}

/**
Expand Down Expand Up @@ -257,4 +267,23 @@ public function setForegroundCountries($foregroundCountries)
$this->_foregroundCountries = (array)$foregroundCountries;
return $this;
}

/**
* Get list of countries with required states
*
* @return \Magento\Directory\Model\Country[]
*/
public function getCountriesWithRequiredStates()
{
$countries = [];
foreach ($this->getItems() as $country) {
/** @var \Magento\Directory\Model\Country $country */
if ($country->getRegionCollection()->getSize() > 0
&& !in_array($country->getId(), $this->countriesWithNotRequiredStates)
) {
$countries[$country->getId()] = $country;
}
}
return $countries;
}
}
13 changes: 2 additions & 11 deletions app/code/Magento/Directory/Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,23 +843,14 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
]
);

/**
* @var $countries array
*/
$countries = [];
foreach ($this->directoryData->getCountryCollection() as $country) {
if ($country->getRegionCollection()->getSize() > 0) {
$countries[] = $country->getId();
}
}

$countries = $this->directoryData->getCountryCollection()->getCountriesWithRequiredStates();
$setup->getConnection()->insert(
$setup->getTable('core_config_data'),
[
'scope' => 'default',
'scope_id' => 0,
'path' => Data::XML_PATH_STATES_REQUIRED,
'value' => implode(',', $countries)
'value' => implode(',', array_keys($countries))
]
);
}
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Directory/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<type name="Magento\Directory\Model\ResourceModel\Country\Collection" shared="false">
<arguments>
<argument name="helperData" xsi:type="object">DirectoryHelperDataProxy</argument>
<argument name="countriesWithNotRequiredStates" xsi:type="array">
<item name="FR" xsi:type="string">FR</item>
<item name="DE" xsi:type="string">DE</item>
</argument>
</arguments>
</type>
<preference for="Magento\Directory\Model\Country\Postcode\ConfigInterface" type="Magento\Directory\Model\Country\Postcode\Config" />
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Email/Model/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function getProcessedTemplateSubject(array $variables)
$this->applyDesignConfig();
$storeId = $this->getDesignConfig()->getStore();
try {
$processedResult = $processor->setStoreId($storeId)->filter($this->getTemplateSubject());
$processedResult = $processor->setStoreId($storeId)->filter(__($this->getTemplateSubject()));
} catch (\Exception $e) {
$this->cancelDesignConfig();
throw new \Magento\Framework\Exception\MailException(__($e->getMessage()), $e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Activate extends Link
*/
public function getCaption()
{
return $this->_row->getStatus() == Integration::STATUS_INACTIVE ? __('Activate') : __('Reauthorize');
return $this->_row->getStatus() != Integration::STATUS_ACTIVE ? __('Activate') : __('Reauthorize');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,34 @@ class Converter implements \Magento\Framework\Config\ConverterInterface
/**#@+
* Array keys for config internal representation.
*/
const API_RESOURCES = 'resources';
const API_RESOURCES = 'resource';

const API_RESOURCE_NAME = 'name';

/**#@-*/

/** @var \Magento\Framework\Acl\AclResource\ProviderInterface */
protected $resourceProvider;

/**
* Initialize dependencies.
*
* @param \Magento\Framework\Acl\AclResource\ProviderInterface $resourceProvider
*/
public function __construct(
\Magento\Framework\Acl\AclResource\ProviderInterface $resourceProvider
) {
$this->resourceProvider = $resourceProvider;
}

/**
* {@inheritdoc}
*/
public function convert($source)
{
$result = [];
$allResources = $this->resourceProvider->getAclResources();
$hashAclResourcesTree = $this->hashResources($allResources[1]['children']);
/** @var \DOMNodeList $integrations */
$integrations = $source->getElementsByTagName('integration');
/** @var \DOMElement $integration */
Expand All @@ -43,9 +59,63 @@ public function convert($source)
continue;
}
$resource = $resource->attributes->getNamedItem('name')->nodeValue;
$result[$integrationName][self::API_RESOURCES][] = $resource;
$resourceNames = $this->addParentsToResource($hashAclResourcesTree, $resource);
foreach ($resourceNames as $name) {
$result[$integrationName][self::API_RESOURCES][] = $name;
}
}
// Remove any duplicates added parents
$result[$integrationName][self::API_RESOURCES] =
array_unique($result[$integrationName][self::API_RESOURCES]);
}
return $result;
}

/**
* Make ACL resource array return a hash with parent-resource-name => [children-resources-names] representation
*
* @param array $resources
* @return array
*/
private function hashResources(array $resources)
{
$output = [];
foreach ($resources as $resource) {
if (isset($resource['children'])) {
$item = $this->hashResources($resource['children']);
} else {
$item = [];
}
$output[$resource['id']] = $item;
}
return $output;
}

/**
* Find parents names of a node in an ACL resource hash and add them to returned array
*
* @param array $resourcesHash
* @param string $nodeName
* @return array
*/
private function addParentsToResource(array $resourcesHash, $nodeName)
{
$output = [];
foreach ($resourcesHash as $resource => $children) {
if ($resource == $nodeName) {
$output = [$resource];
break;
}
if (!empty($children)) {
$names = $this->addParentsToResource($children, $nodeName);
if (!empty($names)) {
$output = array_merge([$resource], $names);
break;
} else {
continue;
}
}
}
return $output;
}
}
Loading

0 comments on commit cebf7e3

Please sign in to comment.