Skip to content

Commit

Permalink
https://github.com/canadasatellite-ca/site/issues/249
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Oct 12, 2021
1 parent 226bd17 commit c77e672
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
# in vendor/magento/module-catalog-search/Model/Layer/Filter/Price.php on line 145»:
# https://github.com/canadasatellite-ca/site/issues/28
!/vendor/magento/module-catalog/Model/Layer/Filter/DataProvider/Price.php
# 2021-10-12 Dmitry Fedyuk https://www.upwork.com/fl/mage2pro
# "`Cart2Quote_Features`: «DateTime::createFromFormat() expects parameter 2 to be string, array given
# in vendor/magento/module-catalog/Model/Webapi/Product/Option/Type/Date.php on line 34»":
# https://github.com/canadasatellite-ca/site/issues/249
!/vendor/magento/module-catalog/Model/Webapi/Product/Option/Type/Date.php
# 2021-05-16 Dmitry Fedyuk https://www.upwork.com/fl/mage2pro
# 1) «Broken reference: the 'skip_gallery_before' tries to reorder itself towards 'product.info.media.image',
# but their parents are different: 'skip_gallery_before.wrapper' and 'product.info.media' respectively»:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\Webapi\Product\Option\Type;

use Magento\Framework\Stdlib\DateTime;

/**
* Catalog product option date validator
*/
class Date extends \Magento\Catalog\Model\Product\Option\Type\Date
{
/**
* {@inheritdoc}
*/
public function validateUserValue($values)
{
if ($this->_dateExists() || $this->_timeExists()) {
return parent::validateUserValue($this->formatValues($values));
}
return $this;
}

/**
* @param array $values
* @return array mixed
*/
protected function formatValues($values)
{
if (isset($values[$this->getOption()->getId()])) {
$value = $values[$this->getOption()->getId()];
$dateTime = \DateTime::createFromFormat(DateTime::DATETIME_PHP_FORMAT, $value);
$values[$this->getOption()->getId()] = [
'date' => $value,
'year' => $dateTime->format('Y'),
'month' => $dateTime->format('m'),
'day' => $dateTime->format('d'),
'hour' => $dateTime->format('H'),
'minute' => $dateTime->format('i'),
'day_part' => $dateTime->format('a'),
];
}

return $values;
}

/**
* @return bool
*/
public function useCalendar()
{
return false;
}
}

0 comments on commit c77e672

Please sign in to comment.