diff --git a/classes/event/BrandModelHandler.php b/classes/event/BrandModelHandler.php index 64235050..3878ce25 100644 --- a/classes/event/BrandModelHandler.php +++ b/classes/event/BrandModelHandler.php @@ -13,20 +13,9 @@ */ class BrandModelHandler extends ModelHandler { - /** @var BrandListStore */ - protected $obListStore; - /** @var Brand */ protected $obElement; - /** - * BrandModelHandler constructor. - */ - public function __construct() - { - $this->obListStore = BrandListStore::instance(); - } - /** * Add listeners * @param \Illuminate\Events\Dispatcher $obEvent @@ -56,7 +45,7 @@ protected function afterSave() { parent::afterSave(); - $this->checkFieldChanges('active', $this->obListStore->active); + $this->checkFieldChanges('active', BrandListStore::instance()->active); } /** @@ -68,7 +57,7 @@ protected function afterDelete() $this->clearSortingList(); if ($this->obElement->active) { - $this->obListStore->active->clear(); + BrandListStore::instance()->active->clear(); } } @@ -77,7 +66,7 @@ protected function afterDelete() */ protected function clearSortingList() { - $this->obListStore->sorting->clear(); + BrandListStore::instance()->sorting->clear(); } /** diff --git a/classes/event/CategoryModelHandler.php b/classes/event/CategoryModelHandler.php index 7d1f4cf7..36473864 100644 --- a/classes/event/CategoryModelHandler.php +++ b/classes/event/CategoryModelHandler.php @@ -16,17 +16,6 @@ class CategoryModelHandler extends ModelHandler /** @var Category */ protected $obElement; - /** @var CategoryListStore */ - protected $obListStore; - - /** - * CategoryModelHandler constructor. - */ - public function __construct() - { - $this->obListStore = CategoryListStore::instance(); - } - /** * Add listeners * @param \Illuminate\Events\Dispatcher $obEvent @@ -36,7 +25,7 @@ public function subscribe($obEvent) parent::subscribe($obEvent); $obEvent->listen('shopaholic.category.update.sorting', function () { - $this->obListStore->top_level->clear(); + CategoryListStore::instance()->top_level->clear(); //Get category ID list $arCategoryIDList = Category::lists('id'); @@ -57,9 +46,9 @@ public function subscribe($obEvent) protected function afterSave() { parent::afterSave(); - $this->obListStore->top_level->clear(); + CategoryListStore::instance()->top_level->clear(); - $this->checkFieldChanges('active', $this->obListStore->active); + $this->checkFieldChanges('active', CategoryListStore::instance()->active); } /** @@ -68,7 +57,7 @@ protected function afterSave() protected function afterDelete() { parent::afterDelete(); - $this->obListStore->top_level->clear(); + CategoryListStore::instance()->top_level->clear(); //Clear parent item cache if (!empty($this->obElement->parent_id)) { @@ -76,7 +65,7 @@ protected function afterDelete() } if ($this->obElement->active) { - $this->obListStore->active->clear(); + CategoryListStore::instance()->active->clear(); } } diff --git a/classes/event/OfferModelHandler.php b/classes/event/OfferModelHandler.php index 6e960cd8..530dadaf 100644 --- a/classes/event/OfferModelHandler.php +++ b/classes/event/OfferModelHandler.php @@ -21,12 +21,6 @@ class OfferModelHandler extends ModelHandler /** @var Offer */ protected $obElement; - /** @var ProductListStore */ - protected $obProductListStore; - - /** @var OfferListStore */ - protected $obListStore; - /** * After save event handler */ @@ -50,7 +44,7 @@ protected function afterDelete() if ($this->obElement->active) { $this->clearProductActiveList(); $this->clearProductItemCache($this->obElement->product_id); - $this->obListStore->active->clear(); + OfferListStore::instance()->active->clear(); } //Get product object @@ -60,8 +54,8 @@ protected function afterDelete() } //Clear sorting product list by offer price - $this->obProductListStore->sorting->clear(ProductListStore::SORT_PRICE_ASC); - $this->obProductListStore->sorting->clear(ProductListStore::SORT_PRICE_DESC); + ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_ASC); + ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_DESC); } /** @@ -104,8 +98,8 @@ protected function checkProductIDField() protected function checkPriceField() { if ($this->obElement->getOriginal('price') != $this->obElement->price_value) { - $this->obListStore->sorting->clear(OfferListStore::SORT_PRICE_ASC); - $this->obListStore->sorting->clear(OfferListStore::SORT_PRICE_DESC); + OfferListStore::instance()->sorting->clear(OfferListStore::SORT_PRICE_ASC); + OfferListStore::instance()->sorting->clear(OfferListStore::SORT_PRICE_DESC); } $bNeedUpdateFlag = @@ -126,8 +120,8 @@ protected function checkPriceField() return; } - $this->obProductListStore->sorting->clear(ProductListStore::SORT_PRICE_ASC); - $this->obProductListStore->sorting->clear(ProductListStore::SORT_PRICE_DESC); + ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_ASC); + ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_DESC); } /** @@ -141,7 +135,7 @@ protected function checkActiveField() } $this->clearProductActiveList(); - $this->obListStore->active->clear(); + OfferListStore::instance()->active->clear(); $obProduct = $this->obElement->product; if (empty($obProduct)) { @@ -167,16 +161,7 @@ protected function clearProductActiveList() return; } - $this->obProductListStore->active->clear(); - } - - /** - * Init store objects - */ - protected function init() - { - $this->obProductListStore = ProductListStore::instance(); - $this->obListStore = OfferListStore::instance(); + ProductListStore::instance()->active->clear(); } /** diff --git a/classes/event/ProductModelHandler.php b/classes/event/ProductModelHandler.php index 347c083c..ccfd7cad 100644 --- a/classes/event/ProductModelHandler.php +++ b/classes/event/ProductModelHandler.php @@ -18,12 +18,6 @@ class ProductModelHandler extends ModelHandler /** @var Product */ protected $obElement; - /** @var ProductListStore */ - protected $obListStore; - - /** @var BrandListStore */ - protected $obBrandListStore; - /** * Add listeners * @param \Illuminate\Events\Dispatcher $obEvent @@ -49,8 +43,8 @@ protected function afterCreate() { parent::afterCreate(); - $this->obListStore->sorting->clear(ProductListStore::SORT_NEW); - $this->obListStore->sorting->clear(ProductListStore::SORT_NO); + ProductListStore::instance()->sorting->clear(ProductListStore::SORT_NEW); + ProductListStore::instance()->sorting->clear(ProductListStore::SORT_NO); } /** @@ -77,18 +71,18 @@ protected function afterDelete() $this->processOfferAfterDelete(); parent::afterDelete(); - $this->obListStore->category->clear($this->obElement->category_id); - $this->obBrandListStore->category->clear($this->obElement->category_id); + ProductListStore::instance()->category->clear($this->obElement->category_id); + BrandListStore::instance()->category->clear($this->obElement->category_id); - $this->obListStore->brand->clear($this->obElement->brand_id); + ProductListStore::instance()->brand->clear($this->obElement->brand_id); - $this->obListStore->sorting->clear(ProductListStore::SORT_PRICE_ASC); - $this->obListStore->sorting->clear(ProductListStore::SORT_PRICE_DESC); - $this->obListStore->sorting->clear(ProductListStore::SORT_NEW); - $this->obListStore->sorting->clear(ProductListStore::SORT_NO); + ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_ASC); + ProductListStore::instance()->sorting->clear(ProductListStore::SORT_PRICE_DESC); + ProductListStore::instance()->sorting->clear(ProductListStore::SORT_NEW); + ProductListStore::instance()->sorting->clear(ProductListStore::SORT_NO); if ($this->obElement->active) { - $this->obListStore->active->clear(); + ProductListStore::instance()->active->clear(); } } @@ -118,7 +112,7 @@ protected function checkActiveField() return; } - $this->obListStore->active->clear(); + ProductListStore::instance()->active->clear(); $this->clearCategoryProductCount($this->obElement->category_id); @@ -144,11 +138,11 @@ protected function checkCategoryIDField() } //Update product ID cache list for category - $this->obListStore->category->clear($this->obElement->category_id); - $this->obListStore->category->clear((int) $this->obElement->getOriginal('category_id')); + ProductListStore::instance()->category->clear($this->obElement->category_id); + ProductListStore::instance()->category->clear((int) $this->obElement->getOriginal('category_id')); - $this->obBrandListStore->category->clear($this->obElement->category_id); - $this->obBrandListStore->category->clear((int) $this->obElement->getOriginal('category_id')); + BrandListStore::instance()->category->clear($this->obElement->category_id); + BrandListStore::instance()->category->clear((int) $this->obElement->getOriginal('category_id')); $this->clearCategoryProductCount($this->obElement->category_id); $this->clearCategoryProductCount((int) $this->obElement->getOriginal('category_id')); @@ -165,8 +159,8 @@ protected function checkBrandIDField() } //Update product ID cache list for brand - $this->obListStore->brand->clear($this->obElement->brand_id); - $this->obListStore->brand->clear((int) $this->obElement->getOriginal('brand_id')); + ProductListStore::instance()->brand->clear($this->obElement->brand_id); + ProductListStore::instance()->brand->clear((int) $this->obElement->getOriginal('brand_id')); } /** @@ -199,8 +193,8 @@ protected function checkAdditionalCategoryList() //Clear product list cache by category ID foreach ($arCategoryIDList as $iCategoryID) { - $this->obListStore->category->clear($iCategoryID); - $this->obBrandListStore->category->clear($iCategoryID); + ProductListStore::instance()->category->clear($iCategoryID); + BrandListStore::instance()->category->clear($iCategoryID); $this->clearCategoryProductCount($iCategoryID); } @@ -218,15 +212,6 @@ protected function clearCategoryProductCount($iCategoryID) } } - /** - * Init store objects - */ - protected function init() - { - $this->obListStore = ProductListStore::instance(); - $this->obBrandListStore = BrandListStore::instance(); - } - /** * Get model class name * @return string diff --git a/classes/item/CategoryItem.php b/classes/item/CategoryItem.php index 03da57ff..9c2b6fc2 100644 --- a/classes/item/CategoryItem.php +++ b/classes/item/CategoryItem.php @@ -44,11 +44,12 @@ * Properties for Shopaholic * @see \Lovata\PropertiesShopaholic\Classes\Event\CategoryModelHandler::extendCategoryItem * - * @method addProductPropertyIDList() + * @property array $property_set_id + * @property \Lovata\PropertiesShopaholic\Classes\Collection\PropertySetCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertySetItem[] $property_set + * * @property array $product_property_list * @property \Lovata\PropertiesShopaholic\Classes\Collection\PropertyCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertyItem[] $product_property * - * @method addOfferPropertyIDList() * @property array $offer_property_list * @property \Lovata\PropertiesShopaholic\Classes\Collection\PropertyCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertyItem[] $offer_property * @@ -209,12 +210,7 @@ protected function getProductCountAttribute() } } - $obProductCollection = ProductCollection::make()->saved(self::class.'_active'); - if (empty($obProductCollection)) { - $obProductCollection = ProductCollection::make()->active()->save(self::class.'_active'); - } - - $iProductCount += $obProductCollection->category($this->id)->count(); + $iProductCount += ProductCollection::make()->active()->category($this->id)->count(); CCache::forever($arCacheTag, $sCacheKey, $iProductCount); $this->setAttribute('product_count', $iProductCount); diff --git a/classes/item/OfferItem.php b/classes/item/OfferItem.php index b66e8e92..7784e11b 100644 --- a/classes/item/OfferItem.php +++ b/classes/item/OfferItem.php @@ -38,6 +38,7 @@ * * Properties for Shopaholic * @see \Lovata\PropertiesShopaholic\Classes\Event\OfferModelHandler::extendOfferItem + * @property array $property_value_array * @property \Lovata\PropertiesShopaholic\Classes\Collection\PropertyCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertyItem[] $property */ class OfferItem extends ElementItem diff --git a/classes/item/ProductItem.php b/classes/item/ProductItem.php index bfc57e94..60ac36e5 100644 --- a/classes/item/ProductItem.php +++ b/classes/item/ProductItem.php @@ -40,6 +40,7 @@ * * Properties for Shopaholic * @see \Lovata\PropertiesShopaholic\Classes\Event\ProductModelHandler::extendProductItem + * @property array $property_value_array * @property \Lovata\PropertiesShopaholic\Classes\Collection\PropertyCollection|\Lovata\PropertiesShopaholic\Classes\Item\PropertyItem[] $property * * Reviews for Shopaholic diff --git a/classes/store/product/ListByCategoryStore.php b/classes/store/product/ListByCategoryStore.php index a7e68c01..4a61989e 100644 --- a/classes/store/product/ListByCategoryStore.php +++ b/classes/store/product/ListByCategoryStore.php @@ -1,6 +1,7 @@ Product::class]; + public $appends = []; + public $purgeable = []; public $fillable = [ 'active', 'name', diff --git a/models/Offer.php b/models/Offer.php index de9d296f..6c85a3df 100644 --- a/models/Offer.php +++ b/models/Offer.php @@ -54,6 +54,9 @@ * Properties for Shopaholic * @see \Lovata\PropertiesShopaholic\Classes\Event\OfferModelHandler::addPropertyMethods * @property array $property + * + * @property \October\Rain\Database\Collection|\Lovata\PropertiesShopaholic\Models\PropertyValueLink[] $property_value + * @method static \October\Rain\Database\Relations\MorphMany|\Lovata\PropertiesShopaholic\Models\PropertyValueLink property_value() */ class Offer extends Model { @@ -84,6 +87,7 @@ class Offer extends Model public $attachOne = ['preview_image' => 'System\Models\File']; public $attachMany = ['images' => 'System\Models\File']; public $belongsTo = ['product' => [Product::class]]; + public $morphMany = []; public $fillable = [ 'active', diff --git a/models/Product.php b/models/Product.php index 1db2cd7f..e8c97578 100644 --- a/models/Product.php +++ b/models/Product.php @@ -60,6 +60,9 @@ * @see \Lovata\PropertiesShopaholic\Classes\Event\ProductModelHandler::addPropertyMethods * @property array $property * + * @property \October\Rain\Database\Collection|\Lovata\PropertiesShopaholic\Models\PropertyValueLink[] $property_value + * @method static \October\Rain\Database\Relations\MorphMany|\Lovata\PropertiesShopaholic\Models\PropertyValueLink property_value() + * * Popularity for Shopaholic * @property int $popularity * @@ -129,6 +132,8 @@ class Product extends Model ], ]; + public $morphMany = []; + public $appends = []; public $purgeable = []; public $fillable = [ diff --git a/models/settings/fields.yaml b/models/settings/fields.yaml index bf996759..dff25a4a 100644 --- a/models/settings/fields.yaml +++ b/models/settings/fields.yaml @@ -6,6 +6,6 @@ tabs: label: lovata.shopaholic::lang.field.check_offer_active type: checkbox currency: - tab: lovata.shopaholic::lang.tab.prices_format + tab: lovata.toolbox::lang.tab.prices_format span: left label: lovata.shopaholic::lang.field.currency \ No newline at end of file diff --git a/updates/version.yaml b/updates/version.yaml index cd9e47c3..ed1ae79b 100644 --- a/updates/version.yaml +++ b/updates/version.yaml @@ -39,4 +39,6 @@ 1.11.0: - 'Adding getPageUrl() method to ProductItem, BrandItem classes.' 1.11.1: - - 'Adding "field.additional_category" value to lang files. Fixed displaying "additional categories" field only for update/preview forms.' \ No newline at end of file + - 'Adding "field.additional_category" value to lang files. Fixed displaying "additional categories" field only for update/preview forms.' +1.11.2: + - 'Fix work with *Store classes in *Handler classes.' \ No newline at end of file