Skip to content

Commit 4bd767c

Browse files
fixes
1 parent 84c12db commit 4bd767c

18 files changed

+338
-17
lines changed

app/base/migrations/CreateCalendarSlotTableMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateCalendarSlotTableMigration extends DBMigration
1313

1414
public function getName(): string
1515
{
16-
return '9.1_'.parent::getName();
16+
return '09.1_'.parent::getName();
1717
}
1818

1919
public function addDBTableDefinition(Table $table): Table

app/base/migrations/CreateCalendarTableMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateCalendarTableMigration extends DBMigration
1313

1414
public function getName(): string
1515
{
16-
return '9_'.parent::getName();
16+
return '09_'.parent::getName();
1717
}
1818

1919
public function addDBTableDefinition(Table $table): Table

app/base/migrations/CreateGiftCardTableMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateGiftCardTableMigration extends DBMigration
1313

1414
public function getName(): string
1515
{
16-
return '8.5_'.parent::getName();
16+
return '08.5_'.parent::getName();
1717
}
1818

1919
public function addDBTableDefinition(Table $table): Table

app/base/migrations/CreateGiftcardRedeemCodeTableMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateGiftcardRedeemCodeTableMigration extends DBMigration
1313

1414
public function getName(): string
1515
{
16-
return '8.6_'.parent::getName();
16+
return '08.6_'.parent::getName();
1717
}
1818

1919
public function addDBTableDefinition(Table $table): Table

app/base/migrations/CreateOrderShipmentHistoryTableMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CreateOrderShipmentHistoryTableMigration extends DBMigration
1414

1515
public function getName(): string
1616
{
17-
return '9.3_'.parent::getName();
17+
return '09.3_'.parent::getName();
1818
}
1919

2020
public function addDBTableDefinition(Table $table): Table

app/base/migrations/CreateStoreCreditTableMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateStoreCreditTableMigration extends DBMigration
1313

1414
public function getName(): string
1515
{
16-
return '8.4_'.parent::getName();
16+
return '08.4_'.parent::getName();
1717
}
1818

1919
public function addDBTableDefinition(Table $table): Table

app/base/migrations/CreateStoreCreditTransactionTableMigration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateStoreCreditTransactionTableMigration extends DBMigration
1313

1414
public function getName(): string
1515
{
16-
return '8.5_'.parent::getName();
16+
return '08.5_'.parent::getName();
1717
}
1818

1919
public function addDBTableDefinition(Table $table): Table

app/site/controllers/Admin/Cms/Media.php

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use App\App;
3030
use App\Base\Abstracts\Controllers\BasePage;
3131
use App\Base\Abstracts\Models\BaseCollection;
32+
use App\Site\Models\Book;
3233
use Degami\Basics\Html\TagElement;
3334
use App\Site\Models\DownloadableProduct;
3435
use Exception;
@@ -335,13 +336,30 @@ public function getFormDefinition(FAPI\Form $form, array &$form_state): FAPI\For
335336
]);
336337
}
337338

338-
if ($this->getRequest()->query->get('product_id')) {
339+
if ($this->getRequest()->query->get('product_type') == 'downloadable' && $this->getRequest()->query->get('product_id')) {
339340
/** @var DownloadableProduct $product */
340341
$product = $this->containerCall([DownloadableProduct::class, 'load'], ['id' => $this->getRequest()->query->get('product_id')]);
341342
$form->addField('product_id', [
342343
'type' => 'hidden',
343344
'default_value' => $product->getId(),
344345
]);
346+
$form->addField('product_type', [
347+
'type' => 'hidden',
348+
'default_value' => 'downloadable',
349+
]);
350+
}
351+
352+
if ($this->getRequest()->query->get('product_type') == 'downloadable' && $this->getRequest()->query->get('product_id')) {
353+
/** @var Book $product */
354+
$product = $this->containerCall([Book::class, 'load'], ['id' => $this->getRequest()->query->get('product_id')]);
355+
$form->addField('product_id', [
356+
'type' => 'hidden',
357+
'default_value' => $product->getId(),
358+
]);
359+
$form->addField('product_type', [
360+
'type' => 'hidden',
361+
'default_value' => 'book',
362+
]);
345363
}
346364

347365
break;
@@ -470,6 +488,58 @@ function ($product) use ($not_in) {
470488
'suffix' => '<br /><br />',
471489
])->addMarkup('<a class="btn btn-danger btn-sm" href="' . $this->getUrl('crud.app.site.controllers.admin.json.downloadablemedia', ['id' => $product->getId()]) . '?page_id=' . $product->getId() . '&action=new">Cancel</a>');
472490

491+
$this->addSubmitButton($form, true);
492+
break;
493+
case 'book_assoc':
494+
$not_in = array_map(
495+
function ($el) {
496+
return $el->page_id;
497+
},
498+
$this->getDb()->book_media_elementList()->where('media_element_id', $media->getId())->fetchAll()
499+
);
500+
501+
$products = array_filter(
502+
array_map(
503+
function ($product) use ($not_in) {
504+
/** @var Book $product */
505+
if (in_array($product->getId(), $not_in)) {
506+
return null;
507+
}
508+
509+
return ['title' => $product->getTitle() . ' - ' . $product->getRewrite()->getUrl(), 'id' => $product->getId()];
510+
},
511+
Book::getCollection()->getItems()
512+
)
513+
);
514+
515+
$products = array_combine(array_column($products, 'id'), array_column($products, 'title'));
516+
517+
$form->addField('product_id', [
518+
'type' => 'select',
519+
'options' => ['' => ''] + $products,
520+
'default_value' => '',
521+
])->addField('media_id', [
522+
'type' => 'hidden',
523+
'default_value' => $media->getId(),
524+
]);
525+
526+
$this->addSubmitButton($form, true);
527+
break;
528+
case 'book_deassoc':
529+
/** @var Book $product */
530+
$product = $this->containerCall([Book::class, 'load'], ['id' => $this->getRequest()->query->get('product_id')]);
531+
$form->addField('product_id', [
532+
'type' => 'hidden',
533+
'default_value' => $product->getId(),
534+
])->addField('media_id', [
535+
'type' => 'hidden',
536+
'default_value' => $media->getId(),
537+
])->addField('confirm', [
538+
'type' => 'markup',
539+
'value' => 'Do you confirm the disassociation of the selected element from the "' . $product->getTitle() . '" product (ID: ' . $product->getId() . ') ?',
540+
'suffix' => '<br /><br />',
541+
])->addMarkup('<a class="btn btn-danger btn-sm" href="' . $this->getUrl('crud.app.site.controllers.admin.json.bookmedia', ['id' => $product->getId()]) . '?page_id=' . $product->getId() . '&action=new">Cancel</a>');
542+
473543
$this->addSubmitButton($form, true);
474544
break;
475545
case 'delete':
@@ -578,8 +648,10 @@ public function formSubmitted(FAPI\Form $form, &$form_state): mixed
578648

579649
if ($values['page_id'] != null) {
580650
$this->containerCall([Page::class, 'load'], ['id' => $values['page_id']])->addMedia($media);
581-
} else if ($values['product_id'] != null) {
651+
} else if ($values['product_type'] == 'downloadable' && $values['product_id'] != null) {
582652
$this->containerCall([DownloadableProduct::class, 'load'], ['id' => $values['product_id']])->addMedia($media);
653+
} else if ($values['product_type'] == 'book' && $values['product_id'] != null) {
654+
$this->containerCall([Book::class, 'load'], ['id' => $values['product_id']])->addMedia($media);
583655
} else {
584656
$this->addSuccessFlashMessage($this->getUtils()->translate("Media Saved."));
585657
}

app/site/controllers/Admin/Commerce/Books.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ public function getFormDefinition(FAPI\Form $form, array &$form_state): FAPI\For
8787

8888
switch ($type) {
8989
case 'edit':
90+
$this->addActionLink(
91+
'media-btn',
92+
'media-btn',
93+
$this->getHtmlRenderer()->getIcon('image') . ' ' . $this->getUtils()->translate('Media', locale: $this->getCurrentLocale()),
94+
$this->getUrl('crud.app.site.controllers.admin.json.bookmedia', ['id' => $this->getRequest()->query->get('product_id')]) . '?product_id=' . $this->getRequest()->query->get('product_id') . '&product_type=book&action=new',
95+
'btn btn-sm btn-light inToolSidePanel'
96+
);
97+
98+
// intentional fall trough
99+
// no break
90100
case 'new':
91101

92102
$product_title = $product_content = '';

app/site/controllers/Admin/Commerce/DownloadableProducts.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ public function getFormDefinition(FAPI\Form $form, array &$form_state): FAPI\For
9393
'media-btn',
9494
'media-btn',
9595
$this->getHtmlRenderer()->getIcon('image') . ' ' . $this->getUtils()->translate('Media', locale: $this->getCurrentLocale()),
96-
$this->getUrl('crud.app.site.controllers.admin.json.downloadablemedia', ['id' => $this->getRequest()->query->get('product_id')]) . '?product_id=' . $this->getRequest()->query->get('product_id') . '&action=new',
96+
$this->getUrl('crud.app.site.controllers.admin.json.downloadablemedia', ['id' => $this->getRequest()->query->get('product_id')]) . '?product_id=' . $this->getRequest()->query->get('product_id') . '&product_type=downloadable&action=new',
9797
'btn btn-sm btn-light inToolSidePanel'
9898
);
9999

100+
// intentional fall trough
101+
// no break
100102
case 'new':
101103

102104
$product_title = $product_content = $product_media = '';

0 commit comments

Comments
 (0)