Skip to content

Commit

Permalink
MAGETWO-69954: Merge branch 'develop' of github.com:magento/magento2c…
Browse files Browse the repository at this point in the history
…e into MAGETWO-69954-PR-9964
  • Loading branch information
ishakhsuvarov committed Jun 19, 2017
2 parents d086759 + 100af87 commit 88234db
Show file tree
Hide file tree
Showing 53 changed files with 820 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public function getCalendarDateHtml()
$yearStart = $this->_catalogProductOptionTypeDate->getYearStart();
$yearEnd = $this->_catalogProductOptionTypeDate->getYearEnd();

$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
/** Escape RTL characters which are present in some locales and corrupt formatting */
$escapedDateFormat = preg_replace('/[^MmDdYy\/\.\-]/', '', $dateFormat);
$calendar = $this->getLayout()->createBlock(
\Magento\Framework\View\Element\Html\Date::class
)->setId(
Expand All @@ -92,7 +95,7 @@ public function getCalendarDateHtml()
)->setImage(
$this->getViewFileUrl('Magento_Theme::calendar.png')
)->setDateFormat(
$this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)
$escapedDateFormat
)->setValue(
$value
)->setYearsRange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function prepareForCart()

if ($this->_dateExists()) {
if ($this->useCalendar()) {
$timestamp += (new \DateTime($value['date']))->getTimestamp();
$timestamp += $this->_localeDate->date($value['date'], null, true, false)->getTimestamp();
} else {
$timestamp += mktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class StockStatusBaseSelectProcessor implements BaseSelectProcessorInterface
*/
private $resource;

/**
* @var \Magento\CatalogInventory\Api\StockConfigurationInterface
*/
private $stockConfig;

/**
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource
*/
Expand All @@ -30,14 +35,18 @@ class StockStatusBaseSelectProcessor implements BaseSelectProcessorInterface
/**
* @param ResourceConnection $resource
* @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource
* @param \Magento\CatalogInventory\Api\StockConfigurationInterface|null $stockConfig
*/
public function __construct(
ResourceConnection $resource,
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null,
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfig = null
) {
$this->resource = $resource;
$this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance()
->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class);
$this->stockConfig = $stockConfig ?: ObjectManager::getInstance()
->get(\Magento\CatalogInventory\Api\StockConfigurationInterface::class);
}

/**
Expand All @@ -50,13 +59,15 @@ public function process(Select $select)
{
$stockStatusTable = $this->indexerStockFrontendResource->getMainTable();

/** @var Select $select */
$select->join(
['stock' => $stockStatusTable],
sprintf('stock.product_id = %s.entity_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
[]
)
->where('stock.stock_status = ?', Stock::STOCK_IN_STOCK);
if (!$this->stockConfig->isShowOutOfStock()) {
/** @var Select $select */
$select->join(
['stock' => $stockStatusTable],
sprintf('stock.product_id = %s.entity_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
[]
)->where('stock.stock_status = ?', Stock::STOCK_IN_STOCK);
}

return $select;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogInventory/Model/Stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Stock extends AbstractExtensibleModel implements StockInterface
*
* @var string
*/
protected $eventObject = 'stock';
protected $_eventObject = 'stock';

const BACKORDERS_NO = 0;

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogInventory/Model/Stock/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Item extends AbstractExtensibleModel implements StockItemInterface
*
* @var string
*/
protected $eventObject = 'item';
protected $_eventObject = 'item';

/**
* Store model manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,33 +477,37 @@ public function getQtyIncrementsDataProvider()
*
* @param $eventName
* @param $methodName
* @param $objectName
*
* @dataProvider eventsDataProvider
*/
public function testDispatchEvents($eventName, $methodName)
public function testDispatchEvents($eventName, $methodName, $objectName)
{
$isCalledWithRightPrefix = 0;
$isObjectNameRight = 0;
$this->eventDispatcher->expects($this->any())->method('dispatch')->with(
$this->callback(function ($arg) use (&$isCalledWithRightPrefix, $eventName) {
$isCalledWithRightPrefix |= ($arg === $eventName);
return true;
}),
$this->anything()
$this->callback(function ($data) use (&$isObjectNameRight, $objectName) {
$isObjectNameRight |= isset($data[$objectName]);
return true;
})
);

$this->item->$methodName();
$this->assertEquals(
1,
(int) $isCalledWithRightPrefix,
sprintf("Event %s doesn't dispatched", $eventName)
$this->assertTrue(
($isCalledWithRightPrefix && $isObjectNameRight),
sprintf('Event "%s" with object name "%s" doesn\'t dispatched properly', $eventName, $objectName)
);
}

public function eventsDataProvider()
{
return [
['cataloginventory_stock_item_save_before', 'beforeSave'],
['cataloginventory_stock_item_save_after', 'afterSave'],
['cataloginventory_stock_item_save_before', 'beforeSave', 'item'],
['cataloginventory_stock_item_save_after', 'afterSave', 'item'],
];
}
}
20 changes: 12 additions & 8 deletions app/code/Magento/CatalogInventory/Test/Unit/Model/StockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,37 @@ public function setUp()
*
* @param $eventName
* @param $methodName
* @param $objectName
*
* @dataProvider eventsDataProvider
*/
public function testDispatchEvents($eventName, $methodName)
public function testDispatchEvents($eventName, $methodName, $objectName)
{
$isCalledWithRightPrefix = 0;
$isObjectNameRight = 0;
$this->eventDispatcher->expects($this->any())->method('dispatch')->with(
$this->callback(function ($arg) use (&$isCalledWithRightPrefix, $eventName) {
$isCalledWithRightPrefix |= ($arg === $eventName);
return true;
}),
$this->anything()
$this->callback(function ($data) use (&$isObjectNameRight, $objectName) {
$isObjectNameRight |= isset($data[$objectName]);
return true;
})
);

$this->stockModel->$methodName();
$this->assertEquals(
1,
(int) $isCalledWithRightPrefix,
sprintf("Event %s doesn't dispatched", $eventName)
$this->assertTrue(
($isCalledWithRightPrefix && $isObjectNameRight),
sprintf('Event "%s" with object name "%s" doesn\'t dispatched properly', $eventName, $objectName)
);
}

public function eventsDataProvider()
{
return [
['cataloginventory_stock_save_before', 'beforeSave'],
['cataloginventory_stock_save_after', 'afterSave'],
['cataloginventory_stock_save_before', 'beforeSave', 'stock'],
['cataloginventory_stock_save_after', 'afterSave', 'stock'],
];
}
}
6 changes: 6 additions & 0 deletions app/code/Magento/CatalogWidget/Block/Product/ProductsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ public function createCollection()
$conditions->collectValidatedAttributes($collection);
$this->sqlBuilder->attachConditionToCollection($collection, $conditions);

/**
* Prevent retrieval of duplicate records. This may occur when multiselect product attribute matches
* several allowed values from condition simultaneously
*/
$collection->distinct(true);

return $collection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
'addStoreFilter',
'setPageSize',
'setCurPage',
'distinct'
])->disableOriginalConstructor()
->getMock();
$collection->expects($this->once())->method('setVisibility')
Expand All @@ -282,6 +283,7 @@ public function testCreateCollection($pagerEnable, $productsCount, $productsPerP
$collection->expects($this->once())->method('addStoreFilter')->willReturnSelf();
$collection->expects($this->once())->method('setPageSize')->with($expectedPageSize)->willReturnSelf();
$collection->expects($this->once())->method('setCurPage')->willReturnSelf();
$collection->expects($this->once())->method('distinct')->willReturnSelf();

$this->collectionFactory->expects($this->once())->method('create')->willReturn($collection);
$this->productsList->setData('conditions_encoded', 'some_serialized_conditions');
Expand Down
33 changes: 21 additions & 12 deletions app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,26 +315,35 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
*/
protected function getDefaultValue($attributeCode)
{
if ($attributeCode === 'country_id') {
return $this->directoryHelper->getDefaultCountry();
}

$customer = $this->getCustomer();
if ($customer === null) {
return null;
}

$attributeValue = null;
switch ($attributeCode) {
case 'prefix':
$attributeValue = $customer->getPrefix();
break;
case 'firstname':
if ($this->getCustomer()) {
return $this->getCustomer()->getFirstname();
}
$attributeValue = $customer->getFirstname();
break;
case 'middlename':
if ($this->getCustomer()) {
return $this->getCustomer()->getMiddlename();
}
$attributeValue = $customer->getMiddlename();
break;
case 'lastname':
if ($this->getCustomer()) {
return $this->getCustomer()->getLastname();
}
$attributeValue = $customer->getLastname();
break;
case 'suffix':
$attributeValue = $customer->getSuffix();
break;
case 'country_id':
return $this->directoryHelper->getDefaultCountry();
}
return null;

return $attributeValue;
}

/**
Expand Down
30 changes: 15 additions & 15 deletions app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ class ProcessCronQueueObserver implements ObserverInterface
protected $_shell;

/**
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
* @var \Magento\Framework\Stdlib\DateTime\DateTime
*/
protected $timezone;
protected $dateTime;

/**
* @var \Symfony\Component\Process\PhpExecutableFinder
Expand All @@ -124,7 +124,7 @@ class ProcessCronQueueObserver implements ObserverInterface
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Framework\App\Console\Request $request
* @param \Magento\Framework\ShellInterface $shell
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
* @param \Magento\Framework\Process\PhpExecutableFinderFactory $phpExecutableFinderFactory
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Framework\App\State $state
Expand All @@ -138,7 +138,7 @@ public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\App\Console\Request $request,
\Magento\Framework\ShellInterface $shell,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
\Magento\Framework\Process\PhpExecutableFinderFactory $phpExecutableFinderFactory,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\App\State $state
Expand All @@ -150,7 +150,7 @@ public function __construct(
$this->_scopeConfig = $scopeConfig;
$this->_request = $request;
$this->_shell = $shell;
$this->timezone = $timezone;
$this->dateTime = $dateTime;
$this->phpExecutableFinder = $phpExecutableFinderFactory->create();
$this->logger = $logger;
$this->state = $state;
Expand All @@ -170,7 +170,7 @@ public function __construct(
public function execute(\Magento\Framework\Event\Observer $observer)
{
$pendingJobs = $this->_getPendingSchedules();
$currentTime = $this->timezone->scopeTimeStamp();
$currentTime = $this->dateTime->gmtTimestamp();
$jobGroupsRoot = $this->_config->getJobs();

$phpPath = $this->phpExecutableFinder->find() ?: 'php';
Expand Down Expand Up @@ -274,7 +274,7 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
);
}

$schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp()))->save();
$schedule->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', $this->dateTime->gmtTimestamp()))->save();

try {
call_user_func_array($callback, [$schedule]);
Expand All @@ -285,7 +285,7 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,

$schedule->setStatus(Schedule::STATUS_SUCCESS)->setFinishedAt(strftime(
'%Y-%m-%d %H:%M:%S',
$this->timezone->scopeTimeStamp()
$this->dateTime->gmtTimestamp()
));
}

Expand Down Expand Up @@ -322,7 +322,7 @@ protected function _generate($groupId)
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$schedulePeriod = $rawSchedulePeriod * self::SECONDS_IN_MINUTE;
if ($lastRun > $this->timezone->scopeTimeStamp() - $schedulePeriod) {
if ($lastRun > $this->dateTime->gmtTimestamp() - $schedulePeriod) {
return $this;
}

Expand All @@ -343,7 +343,7 @@ protected function _generate($groupId)
* save time schedules generation was ran with no expiration
*/
$this->_cache->save(
$this->timezone->scopeTimeStamp(),
$this->dateTime->gmtTimestamp(),
self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT . $groupId,
['crontab'],
null
Expand Down Expand Up @@ -398,7 +398,7 @@ protected function _cleanup($groupId)
'system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_CLEANUP_EVERY,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
if ($lastCleanup > $this->timezone->scopeTimeStamp() - $historyCleanUp * self::SECONDS_IN_MINUTE) {
if ($lastCleanup > $this->dateTime->gmtTimestamp() - $historyCleanUp * self::SECONDS_IN_MINUTE) {
return $this;
}

Expand Down Expand Up @@ -431,7 +431,7 @@ protected function _cleanup($groupId)
Schedule::STATUS_ERROR => $historyFailure * self::SECONDS_IN_MINUTE,
];

$now = $this->timezone->scopeTimeStamp();
$now = $this->dateTime->gmtTimestamp();
/** @var Schedule $record */
foreach ($history as $record) {
$checkTime = $record->getExecutedAt() ? strtotime($record->getExecutedAt()) :
Expand All @@ -443,7 +443,7 @@ protected function _cleanup($groupId)

// save time history cleanup was ran with no expiration
$this->_cache->save(
$this->timezone->scopeTimeStamp(),
$this->dateTime->gmtTimestamp(),
self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId,
['crontab'],
null
Expand Down Expand Up @@ -475,7 +475,7 @@ protected function getConfigSchedule($jobConfig)
*/
protected function saveSchedule($jobCode, $cronExpression, $timeInterval, $exists)
{
$currentTime = $this->timezone->scopeTimeStamp();
$currentTime = $this->dateTime->gmtTimestamp();
$timeAhead = $currentTime + $timeInterval;
for ($time = $currentTime; $time < $timeAhead; $time += self::SECONDS_IN_MINUTE) {
$ts = strftime('%Y-%m-%d %H:%M:00', $time);
Expand Down Expand Up @@ -503,7 +503,7 @@ protected function generateSchedule($jobCode, $cronExpression, $time)
->setCronExpr($cronExpression)
->setJobCode($jobCode)
->setStatus(Schedule::STATUS_PENDING)
->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $this->timezone->scopeTimeStamp()))
->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $this->dateTime->gmtTimestamp()))
->setScheduledAt(strftime('%Y-%m-%d %H:%M', $time));

return $schedule;
Expand Down
Loading

0 comments on commit 88234db

Please sign in to comment.