Skip to content

Commit 8174817

Browse files
committed
feature:
1 parent 84608f8 commit 8174817

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

Component/Grid/GridRepository.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use Loki\AdminComponents\ProviderHandler\ProviderHandlerListing;
1414
use Loki\Components\Component\ComponentRepository;
1515

16+
/**
17+
* @method GridViewModel getViewModel()
18+
*/
1619
class GridRepository extends ComponentRepository
1720
{
1821
public function __construct(
@@ -25,7 +28,7 @@ public function __construct(
2528

2629
public function getNamespace(): string
2730
{
28-
return $this->getComponent()->getViewModel()->getNamespace();
31+
return $this->getViewModel()->getNamespace();
2932
}
3033

3134
// @todo: Remove the requirement for this
@@ -47,7 +50,7 @@ public function getPrimaryKey(): string
4750

4851
public function getItems(): array
4952
{
50-
$searchableFields = $this->getComponent()->getViewModel()->getSearchableFields();
53+
$searchableFields = $this->getViewModel()->getSearchableFields();
5154
$this->getState()->setSearchableFields($searchableFields);
5255

5356
return $this->getProviderHandler()->getItems($this->getProvider(), $this->getState());
@@ -102,7 +105,7 @@ protected function getState(): State
102105

103106
protected function getBlock(): AbstractBlock
104107
{
105-
return $this->getComponent()->getViewModel()->getBlock();
108+
return $this->getViewModel()->getBlock();
106109
}
107110

108111
public function getResourceModel(): ?AbstractDb

ViewModel/Form/Field/EntitySelect.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ private function getGridViewModel(): GridViewModel
8585
return $gridViewModel;
8686
}
8787

88+
/** @var Template $block */
8889
$block = $this->block->getLayout()->createBlock(Template::class);
8990
$block->setNamespace($this->getNamespace());
9091

ViewModel/Options/StoreViewOptions.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
use Magento\Framework\View\Element\Block\ArgumentInterface;
77
use Magento\Framework\Data\OptionSourceInterface;
8+
use Magento\Store\Model\Store;
89
use Magento\Store\Model\StoreManagerInterface;
10+
use Magento\Store\Model\Website;
911

1012
class StoreViewOptions implements ArgumentInterface, OptionSourceInterface
1113
{
@@ -21,7 +23,7 @@ public function toOptionArray(): array
2123
$options[] = ['label' => __('All Store Views'), 'value' => ''];
2224

2325
$websites = $this->storeManager->getWebsites();
24-
uasort($websites, function ($a, $b) {
26+
uasort($websites, function (Website $a, Website $b) {
2527
$soA = (int)$a->getSortOrder();
2628
$soB = (int)$b->getSortOrder();
2729

@@ -42,7 +44,7 @@ public function toOptionArray(): array
4244
/** @var \Magento\Store\Model\Group $group */
4345

4446
$stores = $group->getStores();
45-
usort($stores, function ($a, $b) {
47+
usort($stores, function (Store $a, Store $b) {
4648
$soA = (int)$a->getSortOrder();
4749
$soB = (int)$b->getSortOrder();
4850

ViewModel/ProductImage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Loki\AdminComponents\ViewModel;
44

5-
use Magento\Catalog\Api\Data\ProductInterface;
5+
use Magento\Catalog\Model\Product;
66
use Magento\Catalog\Helper\Image as ImageHelper;
77
use Magento\Framework\View\Element\Block\ArgumentInterface;
88

@@ -13,15 +13,15 @@ public function __construct(
1313
) {
1414
}
1515

16-
public function getThumbnailUrl(ProductInterface $product): string
16+
public function getThumbnailUrl(Product $product): string
1717
{
1818
return $this->imageHelper->init($product, 'product_page_image_small')
1919
->setImageFile($product->getImage()) // image,small_image,thumbnail
2020
->resize(80)
2121
->getUrl();
2222
}
2323

24-
public function getImageUrl(ProductInterface $product): string
24+
public function getImageUrl(Product $product): string
2525
{
2626
return $this->imageHelper->init($product, 'product_page_image_medium')
2727
->setImageFile($product->getImage())

ViewModel/StoreView.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Magento\Framework\View\Element\Block\ArgumentInterface;
66
use Magento\Store\Model\StoreManager;
7+
use Magento\Store\Model\Website;
78

89
class StoreView implements ArgumentInterface
910
{
@@ -18,9 +19,11 @@ public function getStoreHierarchy(array $storeIds): array
1819

1920
foreach ($storeIds as $storeId) {
2021
$store = $this->storeManager->getStore($storeId);
21-
$websites[$store->getWebsiteId()]['selected'] = true;
22-
$websites[$store->getWebsiteId()]['groups'][$store->getStoreGroupId()]['selected'] = true;
23-
$websites[$store->getWebsiteId()]['groups'][$store->getStoreGroupId()]['stores'][$storeId]['selected'] = true;
22+
$websiteId = $store->getWebsiteId();
23+
$groupId = $store->getStoreGroupId();
24+
$websites[$websiteId]['selected'] = true;
25+
$websites[$websiteId]['groups'][$groupId]['selected'] = true;
26+
$websites[$websiteId]['groups'][$groupId]['stores'][$storeId]['selected'] = true;
2427
}
2528

2629
return $websites;
@@ -31,6 +34,10 @@ private function getDefaultHierarchy(): array
3134
{
3235
$websites = [];
3336
foreach ($this->storeManager->getWebsites() as $website) {
37+
if (false === $website instanceof Website) {
38+
continue;
39+
}
40+
3441
$groups = [];
3542
foreach ($website->getGroups() as $group) {
3643
$stores = [];

0 commit comments

Comments
 (0)