Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…to2ce into develop
  • Loading branch information
Dmytro Aponasenko committed Aug 7, 2015
2 parents 2f47898 + 0a1db3c commit dce2e1b
Show file tree
Hide file tree
Showing 281 changed files with 12,290 additions and 6,255 deletions.
20 changes: 18 additions & 2 deletions app/code/Magento/Authorizenet/Model/Directpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class Directpost extends \Magento\Authorizenet\Model\Authorizenet implements Tra
*/
protected $orderFactory;

/**
* @var \Magento\Sales\Api\TransactionRepositoryInterface
*/
protected $transactionRepository;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand All @@ -129,6 +134,7 @@ class Directpost extends \Magento\Authorizenet\Model\Authorizenet implements Tra
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
* @param \Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender
* @param \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
Expand All @@ -151,6 +157,7 @@ public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Quote\Model\QuoteRepository $quoteRepository,
\Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender,
\Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository,
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
Expand All @@ -160,6 +167,7 @@ public function __construct(
$this->quoteRepository = $quoteRepository;
$this->response = $responseFactory->create();
$this->orderSender = $orderSender;
$this->transactionRepository = $transactionRepository;
$this->_code = static::METHOD_CODE;

parent::__construct(
Expand Down Expand Up @@ -795,7 +803,11 @@ protected function declineOrder(\Magento\Sales\Model\Order $order, $message = ''
*/
protected function getRealParentTransactionId($payment)
{
$transaction = $payment->getTransaction($payment->getParentTransactionId());
$transaction = $this->transactionRepository->getByTransactionId(
$payment->getParentTransactionId(),
$payment->getId(),
$payment->getOrder()->getId()
);
return $transaction->getAdditionalInformation(self::REAL_TRANSACTION_ID_KEY);
}

Expand Down Expand Up @@ -851,7 +863,11 @@ public function canCapture()
*/
public function fetchTransactionInfo(\Magento\Payment\Model\InfoInterface $payment, $transactionId)
{
$transaction = $payment->getTransaction($transactionId);
$transaction = $this->transactionRepository->getByTransactionId(
$transactionId,
$payment->getId(),
$payment->getOrder()->getId()
);

$response = $this->getTransactionResponse($transactionId);
if ($response->getXResponseCode() == self::RESPONSE_CODE_APPROVED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public function testAuthorizeSuccess(
$this->assertEquals($this->model, $this->model->authorize($paymentObject, $amount));
foreach ($expectedPaymentFields as $key => $value) {
if ($key == 'getTransactionAdditionalInfo') {
$this->assertEquals($value, $paymentObject->getTransactionAdditionalInfo('token'));
$this->assertEquals($value, $paymentObject->getTransactionAdditionalInfo());
} else {
$this->assertEquals($value, $paymentObject->getData($key), 'Incorrect field in paymentobject: ' . $key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ public function testAuthorizeSuccess(
$this->assertEquals($this->model, $this->model->authorize($paymentObject, $amount));
foreach ($expectedPaymentFields as $key => $value) {
if ($key == 'getTransactionAdditionalInfo') {
$this->assertEquals($value, $paymentObject->getTransactionAdditionalInfo('token'));
$this->assertEquals($value, $paymentObject->getTransactionAdditionalInfo());
} else {
$this->assertEquals($value, $paymentObject->getData($key), 'Incorrect field in paymentobject: ' . $key);
}
Expand Down Expand Up @@ -1385,7 +1385,7 @@ public function authorizeDataProvider()
'processorResponseCode' => '1000',
'processorResponseText' => 'Approved',
],
'getTransactionAdditionalInfo' => self::CC_TOKEN
'getTransactionAdditionalInfo' => ['token' => self::CC_TOKEN]
],
],
'token_with_3dsecure' => [
Expand Down Expand Up @@ -1458,7 +1458,7 @@ public function authorizeDataProvider()
'processorResponseCode' => '1000',
'processorResponseText' => 'Approved',
],
'getTransactionAdditionalInfo' => self::CC_TOKEN
'getTransactionAdditionalInfo' => ['token' => self::CC_TOKEN]
],
],
'token_with_3dsecure_backend' => [
Expand Down Expand Up @@ -1526,7 +1526,7 @@ public function authorizeDataProvider()
'processorResponseCode' => '1000',
'processorResponseText' => 'Approved',
],
'getTransactionAdditionalInfo' => self::CC_TOKEN
'getTransactionAdditionalInfo' => ['token' => self::CC_TOKEN]
],
'appState' => 'adminhtml',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,48 @@
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Model;
namespace Magento\Bundle\Observer;

/**
* Bundle Products Observer
*
* @author Magento Core Team <core@magentocommerce.com>
*/
class Observer
class AppendUpsellProducts
{
/**
* Bundle data
*
* @var \Magento\Bundle\Helper\Data
*/
protected $_bundleData = null;

/**
* Catalog helper
*
* @var \Magento\Catalog\Helper\Catalog
*/
protected $_helperCatalog = null;
protected $bundleData;

/**
* @var \Magento\Bundle\Model\Resource\Selection
*/
protected $_bundleSelection;
protected $bundleSelection;

/**
* @var \Magento\Catalog\Model\Config
*/
protected $_config;
protected $config;

/**
* @var \Magento\Catalog\Model\Product\Visibility
*/
protected $_productVisibility;
protected $productVisibility;

/**
* @param \Magento\Bundle\Helper\Data $bundleData
* @param \Magento\Catalog\Model\Product\Visibility $productVisibility
* @param \Magento\Catalog\Model\Config $config
* @param \Magento\Bundle\Model\Resource\Selection $bundleSelection
* @param \Magento\Catalog\Helper\Catalog $helperCatalog
* @param \Magento\Bundle\Helper\Data $bundleData
*/
public function __construct(
\Magento\Bundle\Helper\Data $bundleData,
\Magento\Catalog\Model\Product\Visibility $productVisibility,
\Magento\Catalog\Model\Config $config,
\Magento\Bundle\Model\Resource\Selection $bundleSelection,
\Magento\Catalog\Helper\Catalog $helperCatalog,
\Magento\Bundle\Helper\Data $bundleData
\Magento\Bundle\Model\Resource\Selection $bundleSelection
) {
$this->_helperCatalog = $helperCatalog;
$this->_bundleData = $bundleData;
$this->_bundleSelection = $bundleSelection;
$this->_config = $config;
$this->_productVisibility = $productVisibility;
$this->bundleData = $bundleData;
$this->productVisibility = $productVisibility;
$this->config = $config;
$this->bundleSelection = $bundleSelection;
}

/**
Expand All @@ -70,15 +55,15 @@ public function __construct(
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function appendUpsellProducts($observer)
public function invoke($observer)
{
/* @var $product \Magento\Catalog\Model\Product */
$product = $observer->getEvent()->getProduct();

/**
* Check is current product type is allowed for bundle selection product type
*/
if (!in_array($product->getTypeId(), $this->_bundleData->getAllowedSelectionTypes())) {
if (!in_array($product->getTypeId(), $this->bundleData->getAllowedSelectionTypes())) {
return $this;
}

Expand All @@ -94,7 +79,7 @@ public function appendUpsellProducts($observer)
}

/* @var $resource \Magento\Bundle\Model\Resource\Selection */
$resource = $this->_bundleSelection;
$resource = $this->bundleSelection;

$productIds = array_keys($collection->getItems());
if ($limit !== null && $limit <= count($productIds)) {
Expand All @@ -112,9 +97,9 @@ public function appendUpsellProducts($observer)

/* @var $bundleCollection \Magento\Catalog\Model\Resource\Product\Collection */
$bundleCollection = $product->getCollection()->addAttributeToSelect(
$this->_config->getProductAttributes()
$this->config->getProductAttributes()
)->addStoreFilter()->addMinimalPrice()->addFinalPrice()->addTaxPercents()->setVisibility(
$this->_productVisibility->getVisibleInCatalogIds()
$this->productVisibility->getVisibleInCatalogIds()
);

if ($limit !== null) {
Expand Down Expand Up @@ -142,50 +127,4 @@ public function appendUpsellProducts($observer)

return $this;
}

/**
* Add price index data for catalog product collection
* only for front end
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function loadProductOptions($observer)
{
$collection = $observer->getEvent()->getCollection();
/* @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
$collection->addPriceData();

return $this;
}

/**
* Setting attribute tab block for bundle
*
* @param \Magento\Framework\DataObject $observer
* @return $this
*/
public function setAttributeTabBlock($observer)
{
$product = $observer->getEvent()->getProduct();
if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
$this->_helperCatalog->setAttributeTabBlock(
'Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes'
);
}
return $this;
}

/**
* Initialize product options renderer with bundle specific params
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function initOptionRenderer(\Magento\Framework\Event\Observer $observer)
{
$block = $observer->getBlock();
$block->addOptionsRenderCfg('bundle', 'Magento\Bundle\Helper\Catalog\Product\Configuration');
return $this;
}
}
22 changes: 22 additions & 0 deletions app/code/Magento/Bundle/Observer/InitOptionRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Observer;

class InitOptionRenderer
{
/**
* Initialize product options renderer with bundle specific params
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function invoke(\Magento\Framework\Event\Observer $observer)
{
$block = $observer->getBlock();
$block->addOptionsRenderCfg('bundle', 'Magento\Bundle\Helper\Catalog\Product\Configuration');
return $this;
}
}
25 changes: 25 additions & 0 deletions app/code/Magento/Bundle/Observer/LoadProductOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Observer;

class LoadProductOptions
{
/**
* Add price index data for catalog product collection
* only for front end
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function invoke($observer)
{
$collection = $observer->getEvent()->getCollection();
/* @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
$collection->addPriceData();

return $this;
}
}
41 changes: 41 additions & 0 deletions app/code/Magento/Bundle/Observer/SetAttributeTabBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Observer;

class SetAttributeTabBlock
{
/**
* Catalog helper
*
* @var \Magento\Catalog\Helper\Catalog
*/
protected $helperCatalog;

/**
* @param \Magento\Catalog\Helper\Catalog $helperCatalog
*/
public function __construct(\Magento\Catalog\Helper\Catalog $helperCatalog)
{
$this->helperCatalog = $helperCatalog;
}

/**
* Setting attribute tab block for bundle
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function invoke($observer)
{
$product = $observer->getEvent()->getProduct();
if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
$this->helperCatalog->setAttributeTabBlock(
'Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes'
);
}
return $this;
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Bundle/etc/adminhtml/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="catalog_product_edit_action">
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="setAttributeTabBlock" />
<observer name="bundle_observer" instance="Magento\Bundle\Observer\SetAttributeTabBlock" method="invoke" />
</event>
<event name="catalog_product_new_action">
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="setAttributeTabBlock" />
<observer name="bundle_observer" instance="Magento\Bundle\Observer\SetAttributeTabBlock" method="invoke" />
</event>
</config>
6 changes: 3 additions & 3 deletions app/code/Magento/Bundle/etc/frontend/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="catalog_product_upsell">
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="appendUpsellProducts" />
<observer name="bundle_observer" instance="Magento\Bundle\Observer\AppendUpsellProducts" method="invoke"/>
</event>
<event name="catalog_product_collection_load_after">
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="loadProductOptions" />
<observer name="bundle_observer" instance="Magento\Bundle\Observer\LoadProductOptions" method="invoke"/>
</event>
<event name="product_option_renderer_init">
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="initOptionRenderer" />
<observer name="bundle_observer" instance="Magento\Bundle\Observer\InitOptionRenderer" method="invoke"/>
</event>
</config>
Loading

0 comments on commit dce2e1b

Please sign in to comment.