Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/2.1-develop' into MAGETWO-80419
Browse files Browse the repository at this point in the history
  • Loading branch information
vzabaznov committed Nov 14, 2017
2 parents 4bf176e + 86c9cad commit 004ce67
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ define([
},

/**
* @returns {Bool}
* @returns {Boolean}
*/
isVaultEnabled: function () {
return this.vaultEnabler.isVaultEnabled();
Expand Down Expand Up @@ -144,10 +144,19 @@ define([
},

/**
* Trigger order placing
* Returns state of place order button
* @returns {Boolean}
*/
isButtonActive: function () {
return this.isActive() && this.isPlaceOrderActionAllowed();
},

/**
* Triggers order placing
*/
placeOrderClick: function () {
if (this.validateCardType()) {
this.isPlaceOrderActionAllowed(false);
$(this.getSelector('submit')).trigger('click');
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@
<button class="action primary checkout"
type="submit"
data-bind="
click: placeOrderClick,
attr: {title: $t('Place Order')},
css: {disabled: !isPlaceOrderActionAllowed()},
enable: isActive()
click: placeOrderClick,
attr: {title: $t('Place Order')},
enable: isButtonActive()
"
disabled>
<span data-bind="i18n: 'Place Order'"></span>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Checkout/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Error!,Error!
"DB exception","DB exception"
"Wrong minimum amount.","Wrong minimum amount."
Message,Message
"<a href=""%1"" onclick=""this.target=\'_blank\'"" class=""print"">Print receipt</a>","<a href=""%1"" onclick=""this.target=\'_blank\'"" class=""print"">Print receipt</a>"
"Print receipt","Print receipt"
"Apply Discount Code","Apply Discount Code"
"Enter discount code","Enter discount code"
"Apply Discount","Apply Discount"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<?php /** @var $block \Magento\Checkout\Block\Onepage\Success */ ?>

<?php if ($block->getCanViewOrder() && $block->getCanPrintOrder()) :?>
<?php /* @escapeNotVerified */ echo __('<a href="%1" onclick="this.target=\'_blank\'" class="print">Print receipt</a>', $block->getPrintUrl()) ?>
<a href="<?php /* @escapeNotVerified */ echo $block->getPrintUrl() ?>" target="_blank" class="print">
<?php /* @escapeNotVerified */ echo __('Print receipt') ?>
</a>
<?php echo $block->getChildHtml() ?>
<?php endif;?>
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function processFreeShipping(\Magento\Quote\Model\Quote\Item\AbstractItem

case Rule::FREE_SHIPPING_ADDRESS:
$address->setFreeShipping(true);
$item->setFreeShipping(true);
break;
}
if ($rule->getStopRulesProcessing()) {
Expand Down
58 changes: 55 additions & 3 deletions app/code/Magento/Rule/Model/Condition/Sql/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

namespace Magento\Rule\Model\Condition\Sql;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Rule\Model\Condition\AbstractCondition;
use Magento\Rule\Model\Condition\Combine;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Catalog\Model\Product;
use Magento\Eav\Model\Entity\Collection\AbstractCollection;

/**
* Class SQL Builder
Expand Down Expand Up @@ -43,12 +48,29 @@ class Builder
*/
protected $_expressionFactory;

/**
* @var AttributeRepositoryInterface
*/
private $attributeRepository;

/**
* EAV collection
*
* @var AbstractCollection
*/
private $eavCollection;

/**
* @param ExpressionFactory $expressionFactory
* @param AttributeRepositoryInterface|null $attributeRepository
*/
public function __construct(ExpressionFactory $expressionFactory)
{
public function __construct(
ExpressionFactory $expressionFactory,
AttributeRepositoryInterface $attributeRepository = null
) {
$this->_expressionFactory = $expressionFactory;
$this->attributeRepository = $attributeRepository ?:
ObjectManager::getInstance()->get(AttributeRepositoryInterface::class);
}

/**
Expand Down Expand Up @@ -125,9 +147,16 @@ protected function _getMappedSqlCondition(AbstractCondition $condition, $value =
throw new \Magento\Framework\Exception\LocalizedException(__('Unknown condition operator'));
}

$defaultValue = 0;
// Check if attribute has a table with default value and add it to the query
if ($this->canAttributeHaveDefaultValue($condition->getAttribute())) {
$defaultField = 'at_' . $condition->getAttribute() . '_default.value';
$defaultValue = $this->_connection->quoteIdentifier($defaultField);
}

$sql = str_replace(
':field',
$this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), 0),
$this->_connection->getIfNullSql($this->_connection->quoteIdentifier($argument), $defaultValue),
$this->_conditionOperatorMap[$conditionOperator]
);

Expand Down Expand Up @@ -177,11 +206,34 @@ public function attachConditionToCollection(
Combine $combine
) {
$this->_connection = $collection->getResource()->getConnection();
$this->eavCollection = $collection;
$this->_joinTablesToCollection($collection, $combine);
$whereExpression = (string)$this->_getMappedSqlCombination($combine);
if (!empty($whereExpression)) {
// Select ::where method adds braces even on empty expression
$collection->getSelect()->where($whereExpression);
}
$this->eavCollection = null;
}

/**
* Check if attribute can have default value
*
* @param string $attributeCode
* @return bool
*/
private function canAttributeHaveDefaultValue($attributeCode)
{
try {
$attribute = $this->attributeRepository->get(Product::ENTITY, $attributeCode);
} catch (NoSuchEntityException $e) {
// It's not exceptional case as we want to check if we have such attribute or not
$attribute = null;
}
$isNotDefaultStoreUsed = $this->eavCollection !== null
? (int)$this->eavCollection->getStoreId() !== (int) $this->eavCollection->getDefaultStoreId()
: false;

return $isNotDefaultStoreUsed && $attribute !== null && !$attribute->isScopeGlobal();
}
}

0 comments on commit 004ce67

Please sign in to comment.