Skip to content

Commit

Permalink
Merge pull request #93 from lovata/develop
Browse files Browse the repository at this point in the history
Release version 1.11.2
  • Loading branch information
kharanenka authored Jul 11, 2018
2 parents 280ffe9 + 5b981e3 commit 0079b38
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 101 deletions.
17 changes: 3 additions & 14 deletions classes/event/BrandModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,7 +45,7 @@ protected function afterSave()
{
parent::afterSave();

$this->checkFieldChanges('active', $this->obListStore->active);
$this->checkFieldChanges('active', BrandListStore::instance()->active);
}

/**
Expand All @@ -68,7 +57,7 @@ protected function afterDelete()
$this->clearSortingList();

if ($this->obElement->active) {
$this->obListStore->active->clear();
BrandListStore::instance()->active->clear();
}
}

Expand All @@ -77,7 +66,7 @@ protected function afterDelete()
*/
protected function clearSortingList()
{
$this->obListStore->sorting->clear();
BrandListStore::instance()->sorting->clear();
}

/**
Expand Down
21 changes: 5 additions & 16 deletions classes/event/CategoryModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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);
}

/**
Expand All @@ -68,15 +57,15 @@ 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)) {
CategoryItem::clearCache($this->obElement->parent_id);
}

if ($this->obElement->active) {
$this->obListStore->active->clear();
CategoryListStore::instance()->active->clear();
}
}

Expand Down
33 changes: 9 additions & 24 deletions classes/event/OfferModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ class OfferModelHandler extends ModelHandler
/** @var Offer */
protected $obElement;

/** @var ProductListStore */
protected $obProductListStore;

/** @var OfferListStore */
protected $obListStore;

/**
* After save event handler
*/
Expand All @@ -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
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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 =
Expand All @@ -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);
}

/**
Expand All @@ -141,7 +135,7 @@ protected function checkActiveField()
}

$this->clearProductActiveList();
$this->obListStore->active->clear();
OfferListStore::instance()->active->clear();

$obProduct = $this->obElement->product;
if (empty($obProduct)) {
Expand All @@ -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();
}

/**
Expand Down
53 changes: 19 additions & 34 deletions classes/event/ProductModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -118,7 +112,7 @@ protected function checkActiveField()
return;
}

$this->obListStore->active->clear();
ProductListStore::instance()->active->clear();

$this->clearCategoryProductCount($this->obElement->category_id);

Expand All @@ -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'));
Expand All @@ -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'));
}

/**
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
12 changes: 4 additions & 8 deletions classes/item/CategoryItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions classes/item/OfferItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions classes/item/ProductItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions classes/store/product/ListByCategoryStore.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Lovata\Shopaholic\Classes\Store\Product;

use DB;
use Event;
use Lovata\Toolbox\Classes\Store\AbstractStoreWithParam;

use Lovata\Shopaholic\Models\Product;
Expand All @@ -14,6 +15,17 @@ class ListByCategoryStore extends AbstractStoreWithParam
{
protected static $instance;

/**
* Clear element ID list
* @param string $sFilterValue
*/
public function clear($sFilterValue)
{
parent::clear($sFilterValue);

Event::fire('shopaholic.product.category.clear', [$sFilterValue]);
}

/**
* Get ID list from database
* @return array
Expand Down
8 changes: 5 additions & 3 deletions models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
* Properties for Shopaholic
* @see \Lovata\PropertiesShopaholic\Classes\Event\CategoryModelHandler::addModelRelationConfig
*
* @property \October\Rain\Database\Collection|\Lovata\PropertiesShopaholic\Models\Property[] $product_property
* @method static \October\Rain\Database\Relations\BelongsToMany|\Lovata\PropertiesShopaholic\Models\Property product_property()
* @property \October\Rain\Database\Collection|\Lovata\PropertiesShopaholic\Models\PropertySet[] $property_set
* @method static \October\Rain\Database\Relations\BelongsToMany|\Lovata\PropertiesShopaholic\Models\PropertySet property_set()
*
* @property \October\Rain\Database\Collection|\Lovata\PropertiesShopaholic\Models\Property[] $product_property
* @property \October\Rain\Database\Collection|\Lovata\PropertiesShopaholic\Models\Property[] $offer_property
* @method static \October\Rain\Database\Relations\BelongsToMany|\Lovata\PropertiesShopaholic\Models\Property offer_property()
*
* @method static $this getByParentID(int $iParentID)
*/
Expand Down Expand Up @@ -105,6 +105,8 @@ class Category extends Model
];
public $hasMany = ['product' => Product::class];

public $appends = [];
public $purgeable = [];
public $fillable = [
'active',
'name',
Expand Down
Loading

0 comments on commit 0079b38

Please sign in to comment.