Skip to content

Commit

Permalink
Merge pull request #5 from magento-firedrakes/codefreeze
Browse files Browse the repository at this point in the history
[Firedrakes] Bug fixes
  • Loading branch information
vpelipenko committed Dec 25, 2014
2 parents 59f1a97 + 787755d commit ea7e61e
Show file tree
Hide file tree
Showing 43 changed files with 1,554 additions and 140 deletions.
56 changes: 31 additions & 25 deletions app/code/Magento/CatalogRule/Model/Rule/Condition/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,106 +8,112 @@
*/
namespace Magento\CatalogRule\Model\Rule\Condition;

/**
* Class Product
*/
class Product extends \Magento\Rule\Model\Condition\Product\AbstractProduct
{
/**
* Validate product attribute value for condition
*
* @param \Magento\Framework\Object $object
* @param \Magento\Framework\Model\AbstractModel $model
* @return bool
*/
public function validate(\Magento\Framework\Object $object)
public function validate(\Magento\Framework\Model\AbstractModel $model)
{
$attrCode = $this->getAttribute();
if ('category_ids' == $attrCode) {
return $this->validateAttribute($object->getAvailableInCategories());
return $this->validateAttribute($model->getAvailableInCategories());
}

$oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null;
$this->_setAttributeValue($object);
$oldAttrValue = $model->hasData($attrCode) ? $model->getData($attrCode) : null;
$this->_setAttributeValue($model);

$result = $this->validateAttribute($object->getData($this->getAttribute()));
$this->_restoreOldAttrValue($object, $oldAttrValue);
$result = $this->validateAttribute($model->getData($this->getAttribute()));
$this->_restoreOldAttrValue($model, $oldAttrValue);

return (bool)$result;
}

/**
* Restore old attribute value
*
* @param \Magento\Framework\Object $object
* @param \Magento\Framework\Model\AbstractModel $model
* @param mixed $oldAttrValue
* @return void
*/
protected function _restoreOldAttrValue($object, $oldAttrValue)
protected function _restoreOldAttrValue(\Magento\Framework\Model\AbstractModel $model, $oldAttrValue)
{
$attrCode = $this->getAttribute();
if (is_null($oldAttrValue)) {
$object->unsetData($attrCode);
$model->unsetData($attrCode);
} else {
$object->setData($attrCode, $oldAttrValue);
$model->setData($attrCode, $oldAttrValue);
}
}

/**
* Set attribute value
*
* @param \Magento\Framework\Object $object
* @param \Magento\Framework\Model\AbstractModel $model
* @return $this
*/
protected function _setAttributeValue($object)
protected function _setAttributeValue(\Magento\Framework\Model\AbstractModel $model)
{
$storeId = $object->getStoreId();
$storeId = $model->getStoreId();
$defaultStoreId = \Magento\Store\Model\Store::DEFAULT_STORE_ID;

if (!isset($this->_entityAttributeValues[$object->getId()])) {
if (!isset($this->_entityAttributeValues[$model->getId()])) {
return $this;
}

$productValues = $this->_entityAttributeValues[$object->getId()];
$productValues = $this->_entityAttributeValues[$model->getId()];

if (!isset($productValues[$storeId]) && !isset($productValues[$defaultStoreId])) {
return $this;
}

$value = isset($productValues[$storeId]) ? $productValues[$storeId] : $productValues[$defaultStoreId];

$value = $this->_prepareDatetimeValue($value, $object);
$value = $this->_prepareMultiselectValue($value, $object);
$value = $this->_prepareDatetimeValue($value, $model);
$value = $this->_prepareMultiselectValue($value, $model);

$model->setData($this->getAttribute(), $value);

$object->setData($this->getAttribute(), $value);
return $this;
}

/**
* Prepare datetime attribute value
*
* @param mixed $value
* @param \Magento\Framework\Object $object
* @param \Magento\Framework\Model\AbstractModel $model
* @return mixed
*/
protected function _prepareDatetimeValue($value, $object)
protected function _prepareDatetimeValue($value, \Magento\Framework\Model\AbstractModel $model)
{
$attribute = $object->getResource()->getAttribute($this->getAttribute());
$attribute = $model->getResource()->getAttribute($this->getAttribute());
if ($attribute && $attribute->getBackendType() == 'datetime') {
$value = strtotime($value);
}

return $value;
}

/**
* Prepare multiselect attribute value
*
* @param mixed $value
* @param \Magento\Framework\Object $object
* @param \Magento\Framework\Model\AbstractModel $model
* @return mixed
*/
protected function _prepareMultiselectValue($value, $object)
protected function _prepareMultiselectValue($value, \Magento\Framework\Model\AbstractModel $model)
{
$attribute = $object->getResource()->getAttribute($this->getAttribute());
$attribute = $model->getResource()->getAttribute($this->getAttribute());
if ($attribute && $attribute->getFrontendInput() == 'multiselect') {
$value = strlen($value) ? explode(',', $value) : [];
}

return $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function _prepareLayout()
'title' => __('Tax Class'),
'class' => 'required-entry',
'required' => true,
'values' => $this->_taxCustomer->toOptionArray(true),
'values' => $this->_taxCustomer->toOptionArray(),
]
);

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ T: {{var telephone}}
{{depend fax}}F: {{var fax}}{{/depend}}
{{depend vat_id}}VAT: {{var vat_id}}{{/depend}}</text>
<oneline>{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}, {{var street}}, {{var city}}, {{var region}} {{var postcode}}, {{var country}}</oneline>
<html><![CDATA[{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}<br/>
<html><![CDATA[{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}{{depend firstname}}<br/>{{/depend}}
{{depend company}}{{var company}}<br />{{/depend}}
{{if street1}}{{var street1}}<br />{{/if}}
{{depend street2}}{{var street2}}<br />{{/depend}}
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/OfflinePayments/Model/Banktransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class Banktransfer extends \Magento\Payment\Model\Method\AbstractMethod
*/
protected $_infoBlockType = 'Magento\Payment\Block\Info\Instructions';

/**
* Availability option
*
* @var bool
*/
protected $_isOffline = true;

/**
* Get instructions text from config
*
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/OfflinePayments/Model/Cashondelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class Cashondelivery extends \Magento\Payment\Model\Method\AbstractMethod
*/
protected $_infoBlockType = 'Magento\Payment\Block\Info\Instructions';

/**
* Availability option
*
* @var bool
*/
protected $_isOffline = true;

/**
* Get instructions text from config
*
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/OfflinePayments/Model/Checkmo.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class Checkmo extends \Magento\Payment\Model\Method\AbstractMethod
*/
protected $_infoBlockType = 'Magento\OfflinePayments\Block\Info\Checkmo';

/**
* Availability option
*
* @var bool
*/
protected $_isOffline = true;

/**
* Assign data to info model instance
*
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/OfflinePayments/Model/Purchaseorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class Purchaseorder extends \Magento\Payment\Model\Method\AbstractMethod
*/
protected $_infoBlockType = 'Magento\OfflinePayments\Block\Info\Purchaseorder';

/**
* Availability option
*
* @var bool
*/
protected $_isOffline = true;

/**
* Assign data to info model instance
*
Expand Down
17 changes: 17 additions & 0 deletions app/code/Magento/Payment/Model/Method/AbstractMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ abstract class AbstractMethod extends \Magento\Framework\Object implements Metho
*/
protected $_isGateway = false;

/**
* Payment Method feature
*
* @var bool
*/
protected $_isOffline = false;

/**
* Payment Method feature
*
Expand Down Expand Up @@ -366,6 +373,16 @@ public function isGateway()
return $this->_isGateway;
}

/**
* Retrieve payment method online/offline flag
*
* @return bool
*/
public function isOffline()
{
return $this->_isOffline;
}

/**
* Flag if we need to run payment initialize while order place
*
Expand Down
19 changes: 12 additions & 7 deletions app/code/Magento/Persistent/Block/Header/Additional.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function __construct(
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
array $data = []
) {
$this->isScopePrivate = true;
$this->_customerViewHelper = $customerViewHelper;
$this->_persistentSessionHelper = $persistentSessionHelper;
$this->customerRepository = $customerRepository;
Expand All @@ -68,12 +69,16 @@ public function getHref()
*/
protected function _toHtml()
{
$persistentName = $this->_escaper->escapeHtml(
$this->_customerViewHelper->getCustomerName(
$this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId())
)
);
return '<span><a ' . $this->getLinkAttributes() . ' >' . $this->escapeHtml(__('(Not %1?)', $persistentName))
. '</a></span>';
if ($this->_persistentSessionHelper->getSession()->getCustomerId()) {
$persistentName = $this->escapeHtml(
$this->_customerViewHelper->getCustomerName(
$this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId())
)
);
return '<span><a ' . $this->getLinkAttributes() . ' >' . __('(Not %1?)', $persistentName)
. '</a></span>';
}

return '';
}
}
73 changes: 73 additions & 0 deletions app/code/Magento/Persistent/Model/Layout/DepersonalizePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
*/
namespace Magento\Persistent\Model\Layout;

/**
* Class DepersonalizePlugin
*/
class DepersonalizePlugin
{
/**
* @var \Magento\Persistent\Model\Session
*/
protected $persistentSession;

/**
* @var \Magento\Framework\App\RequestInterface
*/
protected $request;

/**
* @var \Magento\Framework\Module\Manager
*/
protected $moduleManager;

/**
* @var \Magento\PageCache\Model\Config
*/
protected $cacheConfig;

/**
* Constructor
*
* @param \Magento\Persistent\Model\Session $persistentSession
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Framework\Module\Manager $moduleManager
* @param \Magento\PageCache\Model\Config $cacheConfig
*/
public function __construct(
\Magento\Persistent\Model\Session $persistentSession,
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\Module\Manager $moduleManager,
\Magento\PageCache\Model\Config $cacheConfig
) {
$this->persistentSession = $persistentSession;
$this->request = $request;
$this->moduleManager = $moduleManager;
$this->cacheConfig = $cacheConfig;
}

/**
* After generate Xml
*
* @param \Magento\Framework\View\LayoutInterface $subject
* @param \Magento\Framework\View\LayoutInterface $result
* @return \Magento\Framework\View\LayoutInterface
*/
public function afterGenerateXml(
\Magento\Framework\View\LayoutInterface $subject,
\Magento\Framework\View\LayoutInterface $result
) {
if ($this->moduleManager->isEnabled('Magento_PageCache')
&& $this->cacheConfig->isEnabled()
&& !$this->request->isAjax()
&& $subject->isCacheable()
) {
$this->persistentSession->setCustomerId(null);
}

return $result;
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Persistent/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"magento/module-customer": "0.42.0-beta1",
"magento/module-sales": "0.42.0-beta1",
"magento/module-cron": "0.42.0-beta1",
"magento/module-page-cache": "0.42.0-beta1",
"magento/framework": "0.42.0-beta1",
"magento/magento-composer-installer": "*"
},
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Persistent/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\View\Layout">
<plugin name="persistent-session-depersonalize"
type="Magento\Persistent\Model\Layout\DepersonalizePlugin"
sortOrder="10"
/>
</type>
</config>
1 change: 1 addition & 0 deletions app/code/Magento/Persistent/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<module name="Magento_Persistent" schema_version="2.0.0">
<sequence>
<module name="Magento_Checkout"/>
<module name="Magento_PageCache"/>
</sequence>
</module>
</config>
11 changes: 8 additions & 3 deletions app/code/Magento/Rule/Model/Condition/AbstractCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,12 +832,17 @@ protected function _compareValues($validatedValue, $value, $strict = true)
}

/**
* @param \Magento\Framework\Object $object
* @param \Magento\Framework\Model\AbstractModel $model
* @return bool
*/
public function validate(\Magento\Framework\Object $object)
public function validate(\Magento\Framework\Model\AbstractModel $model)
{
return $this->validateAttribute($object->getData($this->getAttribute()));
if (!$model->hasData($this->getAttribute())) {
$model->load($model->getId());
}
$attributeValue = $model->getData($this->getAttribute());

return $this->validateAttribute($attributeValue);
}

/**
Expand Down
Loading

0 comments on commit ea7e61e

Please sign in to comment.