42 $this->
_init(
'design_change',
'design_change_id');
54 if ($date = $object->getDateFrom()) {
55 $object->setDateFrom($this->dateTime->formatDate($date));
57 $object->setDateFrom(
null);
60 if ($date = $object->getDateTo()) {
61 $object->setDateTo($this->dateTime->formatDate($date));
63 $object->setDateTo(
null);
66 if ($object->getDateFrom() !==
null 67 && $object->getDateTo() !==
null 68 && (new \DateTime($object->getDateFrom()))->getTimestamp()
69 > (new \DateTime($object->getDateTo()))->getTimestamp()
71 throw new \Magento\Framework\Exception\LocalizedException(
72 __(
'The start date can\'t follow the end date.')
77 $object->getStoreId(),
78 $object->getDateFrom(),
84 throw new \Magento\Framework\Exception\LocalizedException(
85 __(
'The date range for this design change overlaps another design change for the specified store.')
89 if ($object->getDateFrom() ===
null) {
92 if ($object->getDateTo() ===
null) {
96 parent::_beforeSave($object);
115 [
'main_table' => $this->
getTable(
'design_change')]
117 'main_table.store_id = :store_id' 119 'main_table.design_change_id <> :current_id' 122 $dateConditions = [
'date_to IS NULL AND date_from IS NULL'];
124 if ($dateFrom !==
null) {
125 $dateConditions[] =
':date_from BETWEEN date_from AND date_to';
126 $dateConditions[] =
':date_from >= date_from and date_to IS NULL';
127 $dateConditions[] =
':date_from <= date_to and date_from IS NULL';
129 $dateConditions[] =
'date_from IS NULL';
132 if ($dateTo !==
null) {
133 $dateConditions[] =
':date_to BETWEEN date_from AND date_to';
134 $dateConditions[] =
':date_to >= date_from AND date_to IS NULL';
135 $dateConditions[] =
':date_to <= date_to AND date_from IS NULL';
137 $dateConditions[] =
'date_to IS NULL';
140 if ($dateFrom ===
null && $dateTo !==
null) {
141 $dateConditions[] =
'date_to <= :date_to OR date_from <= :date_to';
144 if ($dateFrom !==
null && $dateTo ===
null) {
145 $dateConditions[] =
'date_to >= :date_from OR date_from >= :date_from';
148 if ($dateFrom !==
null && $dateTo !==
null) {
149 $dateConditions[] =
'date_from BETWEEN :date_from AND :date_to';
150 $dateConditions[] =
'date_to BETWEEN :date_from AND :date_to';
151 }
elseif ($dateFrom ===
null && $dateTo ===
null) {
152 $dateConditions = [];
156 if (!empty($dateConditions)) {
157 $condition =
'(' . implode(
') OR (', $dateConditions) .
')';
161 $bind = [
'store_id' => (int)
$storeId,
'current_id' => (
int)$currentId];
163 if ($dateTo !==
null) {
164 $bind[
'date_to'] = $dateTo;
166 if ($dateFrom !==
null) {
167 $bind[
'date_from'] = $dateFrom;
184 [
'main_table' => $this->
getTable(
'design_change')]
186 'store_id = :store_id' 188 'date_from <= :required_date or date_from IS NULL' 190 'date_to >= :required_date or date_to IS NULL' 193 $bind = [
'store_id' => (int)
$storeId,
'required_date' => $date];
loadChange($storeId, $date)
elseif(isset( $params[ 'redirect_parent']))
_init($mainTable, $idFieldName)
_beforeSave(\Magento\Framework\Model\AbstractModel $object)
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, DateTime $dateTime, $connectionName=null)
_checkIntersection($storeId, $dateFrom, $dateTo, $currentId)