Skip to content

Commit

Permalink
Merge pull request #299 from magento-folks/checkout
Browse files Browse the repository at this point in the history
[Folks+South+Troll]Checkou UI rendering
  • Loading branch information
Shkolyarenko, Serhiy(sshkolyarenko) committed May 16, 2015
2 parents 9db84b2 + d4ac936 commit 7689e4d
Show file tree
Hide file tree
Showing 418 changed files with 14,495 additions and 3,621 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ atlassian*
!/pub/media/wysiwyg/.htaccess
/pub/media/tmp/*
!/pub/media/tmp/.htaccess
/pub/media/captcha/*
/pub/static/*
!/pub/static/.htaccess

Expand Down
3 changes: 0 additions & 3 deletions app/code/Magento/Backend/Block/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Context extends \Magento\Framework\View\Element\Context
* @param \Magento\Framework\View\LayoutInterface $layout
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Framework\TranslateInterface $translator
* @param \Magento\Framework\App\CacheInterface $cache
* @param \Magento\Framework\View\DesignInterface $design
* @param \Magento\Framework\Session\SessionManagerInterface $session
Expand All @@ -47,7 +46,6 @@ public function __construct(
\Magento\Framework\View\LayoutInterface $layout,
\Magento\Framework\Event\ManagerInterface $eventManager,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\TranslateInterface $translator,
\Magento\Framework\App\CacheInterface $cache,
\Magento\Framework\View\DesignInterface $design,
\Magento\Framework\Session\SessionManagerInterface $session,
Expand All @@ -69,7 +67,6 @@ public function __construct(
$layout,
$eventManager,
$urlBuilder,
$translator,
$cache,
$design,
$session,
Expand Down
3 changes: 0 additions & 3 deletions app/code/Magento/Backend/Block/Template/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Context extends \Magento\Framework\View\Element\Template\Context
* @param \Magento\Framework\View\LayoutInterface $layout
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Framework\TranslateInterface $translator
* @param \Magento\Framework\App\CacheInterface $cache
* @param \Magento\Framework\View\DesignInterface $design
* @param \Magento\Framework\Session\Generic $session
Expand Down Expand Up @@ -81,7 +80,6 @@ public function __construct(
\Magento\Framework\View\LayoutInterface $layout,
\Magento\Framework\Event\ManagerInterface $eventManager,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\TranslateInterface $translator,
\Magento\Framework\App\CacheInterface $cache,
\Magento\Framework\View\DesignInterface $design,
\Magento\Framework\Session\Generic $session,
Expand Down Expand Up @@ -117,7 +115,6 @@ public function __construct(
$layout,
$eventManager,
$urlBuilder,
$translator,
$cache,
$design,
$session,
Expand Down
3 changes: 0 additions & 3 deletions app/code/Magento/Backend/Block/Widget/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Context extends \Magento\Backend\Block\Template\Context
* @param \Magento\Framework\View\LayoutInterface $layout
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Framework\TranslateInterface $translator
* @param \Magento\Framework\App\CacheInterface $cache
* @param \Magento\Framework\View\DesignInterface $design
* @param \Magento\Framework\Session\Generic $session
Expand Down Expand Up @@ -66,7 +65,6 @@ public function __construct(
\Magento\Framework\View\LayoutInterface $layout,
\Magento\Framework\Event\ManagerInterface $eventManager,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\TranslateInterface $translator,
\Magento\Framework\App\CacheInterface $cache,
\Magento\Framework\View\DesignInterface $design,
\Magento\Framework\Session\Generic $session,
Expand Down Expand Up @@ -99,7 +97,6 @@ public function __construct(
$layout,
$eventManager,
$urlBuilder,
$translator,
$cache,
$design,
$session,
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/Bundle/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
<plugin name="append_bundle_data_to_order" type="Magento\Bundle\Model\Plugin\QuoteItem"/>
</type>
<type name="Magento\Catalog\Helper\Product\ConfigurationPool">
<arguments>
<argument name="instancesByType" xsi:type="array">
<item name="bundle" xsi:type="object">Magento\Bundle\Helper\Catalog\Product\Configuration</item>
</argument>
</arguments>
</type>
</config>
16 changes: 16 additions & 0 deletions app/code/Magento/Bundle/etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Helper\Product\ConfigurationPool">
<arguments>
<argument name="instancesByType" xsi:type="array">
<item name="bundle" xsi:type="object">Magento\Bundle\Helper\Catalog\Product\Configuration</item>
</argument>
</arguments>
</type>
</config>
16 changes: 16 additions & 0 deletions app/code/Magento/Bundle/etc/webapi_soap/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Helper\Product\ConfigurationPool">
<arguments>
<argument name="instancesByType" xsi:type="array">
<item name="bundle" xsi:type="object">Magento\Bundle\Helper\Catalog\Product\Configuration</item>
</argument>
</arguments>
</type>
</config>
10 changes: 10 additions & 0 deletions app/code/Magento/Captcha/Controller/Refresh/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ public function __construct(Context $context, \Magento\Captcha\Helper\Data $capt
public function execute()
{
$formId = $this->_request->getPost('formId');
if (null === $formId) {
try {
$params = \Zend_Json::decode($this->_request->getContent());
$formId = isset($params['formId']) ? $params['formId'] : null;
} catch (\Zend_Json_Exception $exception) {
$formId = null;
}
}
$captchaModel = $this->captchaHelper->getCaptcha($formId);
$captchaModel->generate();

$block = $this->_view->getLayout()->createBlock($captchaModel->getBlockName());
$block->setFormId($formId)->setIsAjax(true)->toHtml();
$this->_response->representJson(json_encode(['imgSrc' => $captchaModel->getImgSrc()]));
Expand Down
128 changes: 128 additions & 0 deletions app/code/Magento/Captcha/Model/Checkout/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Captcha\Model\Checkout;

class ConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface
{
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;

/**
* @var \Magento\Captcha\Helper\Data
*/
protected $captchaData;

/**
* @var array
*/
protected $formIds;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Captcha\Helper\Data $captchaData
* @param array $formIds
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Captcha\Helper\Data $captchaData,
array $formIds
) {
$this->storeManager = $storeManager;
$this->captchaData = $captchaData;
$this->formIds = $formIds;
}

/**
* {@inheritdoc}
*/
public function getConfig()
{
$config = [];
foreach ($this->formIds as $formId) {
$config['captcha'][$formId] = [
'isCaseSensitive' => $this->isCaseSensitive($formId),
'imageHeight' => $this->getImageHeight($formId),
'imageSrc' => $this->getImageSrc($formId),
'refreshUrl' => $this->getRefreshUrl(),
'isRequired' => $this->isRequired($formId)
];
}
return $config;
}

/**
* Returns is captcha case sensitive
*
* @param string $formId
* @return bool
*/
protected function isCaseSensitive($formId)
{
return (boolean)$this->getCaptchaModel($formId)->isCaseSensitive();
}

/**
* Returns captcha image height
*
* @param string $formId
* @return int
*/
protected function getImageHeight($formId)
{
return $this->getCaptchaModel($formId)->getHeight();
}

/**
* Returns captcha image source path
*
* @param string $formId
* @return string
*/
protected function getImageSrc($formId)
{
if ($this->isRequired($formId)) {
$captcha = $this->getCaptchaModel($formId);
$captcha->generate();
return $captcha->getImgSrc();
}
return '';
}

/**
* Returns URL to controller action which returns new captcha image
*
* @return string
*/
protected function getRefreshUrl()
{
$store = $this->storeManager->getStore();
return $store->getUrl('captcha/refresh', ['_secure' => $store->isCurrentlySecure()]);
}

/**
* Whether captcha is required to be inserted to this form
*
* @param string $formId
* @return bool
*/
protected function isRequired($formId)
{
return (boolean)$this->getCaptchaModel($formId)->isRequired();
}

/**
* Return captcha model for specified form
*
* @param string $formId
* @return \Magento\Captcha\Model\ModelInterface
*/
protected function getCaptchaModel($formId)
{
return $this->captchaData->getCaptcha($formId);
}
}
60 changes: 60 additions & 0 deletions app/code/Magento/Captcha/Model/Checkout/Plugin/Validation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Captcha\Model\Checkout\Plugin;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\InputException;

class Validation
{
/**
* @var \Magento\Captcha\Helper\Data
*/
protected $captchaHelper;

/**
* @var array
*/
protected $formIds;

/**
* @param \Magento\Captcha\Helper\Data $captchaHelper
* @param array $formIds
*/
public function __construct(
\Magento\Captcha\Helper\Data $captchaHelper,
array $formIds
) {
$this->captchaHelper = $captchaHelper;
$this->formIds = $formIds;
}

/**
* @param \Magento\Quote\Model\AddressAdditionalDataProcessor $subject
* @param \Magento\Quote\Api\Data\AddressAdditionalDataInterface $additionalData
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\InputException
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeProcess(
\Magento\Quote\Model\AddressAdditionalDataProcessor $subject,
\Magento\Quote\Api\Data\AddressAdditionalDataInterface $additionalData
) {
$formId = $additionalData->getExtensionAttributes()->getCaptchaFormId();
$captchaText = $additionalData->getExtensionAttributes()->getCaptchaString();

if ($formId !== null && !in_array($formId, $this->formIds)) {
throw new NoSuchEntityException(__('Provided form does not exist'));
}
$captchaModel = $this->captchaHelper->getCaptcha($formId);
if ($captchaModel->isRequired()) {
if (!$captchaModel->isCorrect($captchaText)) {
throw new InputException(__('Incorrect CAPTCHA'));
}
}
}
}
Loading

0 comments on commit 7689e4d

Please sign in to comment.