Skip to content

Commit

Permalink
Merge pull request #83 from lovata/develop
Browse files Browse the repository at this point in the history
Release version 1.9.0
  • Loading branch information
kharanenka authored Jun 22, 2018
2 parents ff11f11 + cf71d2a commit a589add
Show file tree
Hide file tree
Showing 54 changed files with 1,450 additions and 1,462 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ before_script:
cd ..;
mkdir -p ./october/plugins/lovata/shopaholic;
mv !(october) october/plugins/lovata/shopaholic;
FOLDER_PATH=$(pwd);
ln -s $FOLDER_PATH/october/plugins/lovata/ $FOLDER_PATH/october/tests/fixtures/plugins/lovata;
cd october/plugins/lovata/shopaholic;
fi

Expand Down
37 changes: 0 additions & 37 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
use Event;
use System\Classes\PluginBase;

use Lovata\Shopaholic\Classes\Helper\PriceHelper;

use Lovata\Shopaholic\Classes\Item\BrandItem;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
use Lovata\Shopaholic\Classes\Item\OfferItem;
use Lovata\Shopaholic\Classes\Item\ProductItem;

use Lovata\Shopaholic\Classes\Collection\BrandCollection;
use Lovata\Shopaholic\Classes\Collection\CategoryCollection;
use Lovata\Shopaholic\Classes\Collection\OfferCollection;
use Lovata\Shopaholic\Classes\Collection\ProductCollection;

use Lovata\Shopaholic\Classes\Store\BrandListStore;
use Lovata\Shopaholic\Classes\Store\CategoryListStore;
use Lovata\Shopaholic\Classes\Store\ProductListStore;
use Lovata\Shopaholic\Classes\Store\OfferListStore;

use Lovata\Shopaholic\Classes\Event\BrandModelHandler;
use Lovata\Shopaholic\Classes\Event\CategoryModelHandler;
use Lovata\Shopaholic\Classes\Event\OfferModelHandler;
Expand All @@ -33,9 +16,6 @@
*/
class Plugin extends PluginBase
{
const NAME = 'shopaholic';
const CACHE_TAG = 'shopaholic';

/** @var array Plugin dependencies */
public $require = ['Lovata.Toolbox'];

Expand Down Expand Up @@ -82,23 +62,6 @@ public function registerSettings()
*/
public function boot()
{
$this->app->singleton(PriceHelper::class, PriceHelper::class);

$this->app->bind(BrandItem::class, BrandItem::class);
$this->app->bind(CategoryItem::class, CategoryItem::class);
$this->app->bind(OfferItem::class, OfferItem::class);
$this->app->bind(ProductItem::class, ProductItem::class);

$this->app->bind(BrandCollection::class, BrandCollection::class);
$this->app->bind(CategoryCollection::class, CategoryCollection::class);
$this->app->bind(OfferCollection::class, OfferCollection::class);
$this->app->bind(ProductCollection::class, ProductCollection::class);

$this->app->singleton(BrandListStore::class, BrandListStore::class);
$this->app->singleton(CategoryListStore::class, CategoryListStore::class);
$this->app->singleton(OfferListStore::class, OfferListStore::class);
$this->app->singleton(ProductListStore::class, ProductListStore::class);

$this->addEventListener();
}

Expand Down
55 changes: 8 additions & 47 deletions classes/collection/BrandCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,28 @@
/**
* Class BrandCollection
* @package Lovata\Shopaholic\Classes\Collection
* @author Andrey Kharanenka, [email protected], LOVATA Group
* @author Andrey Kharanenka, [email protected], LOVATA Group
*
* @see \Lovata\Shopaholic\Tests\Unit\Collection\BrandCollectionTest
* @link https://github.com/lovata/oc-shopaholic-plugin/wiki/BrandCollection
* @see \Lovata\Shopaholic\Tests\Unit\Collection\BrandCollectionTest
* @link https://github.com/lovata/oc-shopaholic-plugin/wiki/BrandCollection
*
* Search for Shopaholic, Sphinx for Shopaholic
* @method $this search(string $sSearch)
*/
class BrandCollection extends ElementCollection
{
/** @var BrandListStore */
protected $obBrandListStore;

/**
* BrandCollection constructor.
* @param BrandListStore $obBrandListStore
*/
public function __construct(BrandListStore $obBrandListStore)
{
$this->obBrandListStore = $obBrandListStore;
parent::__construct();
}
const ITEM_CLASS = BrandItem::class;

/**
* Sort list
* @return $this
*/
public function sort()
{
if (!$this->isClear() && $this->isEmpty()) {
return $this->returnThis();
}

//Get sorting list
$arResultIDList = $this->obBrandListStore->getBySorting();
if (empty($arResultIDList)) {
return $this->clear();
}

if ($this->isClear()) {
$this->arElementIDList = $arResultIDList;
$arResultIDList = BrandListStore::instance()->sorting->get();

return $this->returnThis();
}

$this->arElementIDList = array_intersect($arResultIDList, $this->arElementIDList);

return $this->returnThis();
return $this->applySorting($arResultIDList);
}

/**
Expand All @@ -65,7 +39,7 @@ public function sort()
*/
public function active()
{
$arResultIDList = $this->obBrandListStore->getActiveList();
$arResultIDList = BrandListStore::instance()->active->get();

return $this->intersect($arResultIDList);
}
Expand All @@ -78,21 +52,8 @@ public function active()
*/
public function category($iCategoryID)
{
$arResultIDList = $this->obBrandListStore->getByCategory($iCategoryID);
$arResultIDList = BrandListStore::instance()->category->get($iCategoryID);

return $this->intersect($arResultIDList);
}

/**
* Make element item
* @see \Lovata\Shopaholic\Tests\Unit\Collection\BrandCollectionTest::testCollectionItem()
* @param int $iElementID
* @param \Lovata\Shopaholic\Models\Brand $obElement
*
* @return BrandItem
*/
protected function makeItem($iElementID, $obElement = null)
{
return BrandItem::make($iElementID, $obElement);
}
}
32 changes: 10 additions & 22 deletions classes/collection/CategoryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,7 @@
*/
class CategoryCollection extends ElementCollection
{
/** @var CategoryListStore */
protected $obCategoryListStore;

/**
* CategoryCollection constructor.
* @param CategoryListStore $obCategoryListStore
*/
public function __construct(CategoryListStore $obCategoryListStore)
{
$this->obCategoryListStore = $obCategoryListStore;
parent::__construct();
}
const ITEM_CLASS = CategoryItem::class;

/**
* Set to element ID list top level category ID list
Expand All @@ -38,21 +27,20 @@ public function __construct(CategoryListStore $obCategoryListStore)
*/
public function tree()
{
$this->arElementIDList = $this->obCategoryListStore->getTopLevelList();
$arResultIDList = CategoryListStore::instance()->top_level->get();

return $this->returnThis();
return $this->applySorting($arResultIDList);
}

/**
* Make element item
* @see \Lovata\Shopaholic\Tests\Unit\Collection\CategoryCollectionTest::testCollectionItem()
* @param int $iElementID
* @param \Lovata\Shopaholic\Models\Category $obElement
*
* @return CategoryItem
* Apply filter by active field
* @see \Lovata\Shopaholic\Tests\Unit\Collection\CategoryCollectionTest::testActiveList()
* @return $this
*/
protected function makeItem($iElementID, $obElement = null)
public function active()
{
return CategoryItem::make($iElementID, $obElement);
$arResultIDList = CategoryListStore::instance()->active->get();

return $this->intersect($arResultIDList);
}
}
49 changes: 5 additions & 44 deletions classes/collection/OfferCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,7 @@
*/
class OfferCollection extends ElementCollection
{
/** @var OfferListStore */
protected $obOfferListStore;

/**
* OfferCollection constructor.
* @param OfferListStore $obOfferListStore
*/
public function __construct(OfferListStore $obOfferListStore)
{
$this->obOfferListStore = $obOfferListStore;
parent::__construct();
}
const ITEM_CLASS = OfferItem::class;

/**
* Sort list by
Expand All @@ -40,49 +29,21 @@ public function __construct(OfferListStore $obOfferListStore)
*/
public function sort($sSorting)
{
if (!$this->isClear() && $this->isEmpty()) {
return $this->returnThis();
}

//Get sorting list
$arResultIDList = $this->obOfferListStore->getBySorting($sSorting);
if (empty($arResultIDList)) {
return $this->clear();
}

if ($this->isClear()) {
$this->arElementIDList = $arResultIDList;
$arResultIDList = OfferListStore::instance()->sorting->get($sSorting);

return $this->returnThis();
}

$this->arElementIDList = array_intersect($arResultIDList, $this->arElementIDList);

return $this->returnThis();
return $this->applySorting($arResultIDList);
}

/**
* Apply filter by active product list
* Apply filter by active field
* @see \Lovata\Shopaholic\Tests\Unit\Collection\OfferCollectionTest::testActiveList()
* @return $this
*/
public function active()
{
$arResultIDList = $this->obOfferListStore->getActiveList();
$arResultIDList = OfferListStore::instance()->active->get();

return $this->intersect($arResultIDList);
}

/**
* Make element item
* @see \Lovata\Shopaholic\Tests\Unit\Collection\OfferCollectionTest::testCollectionItem()
* @param int $iElementID
* @param \Lovata\Shopaholic\Models\Offer $obElement
*
* @return OfferItem
*/
protected function makeItem($iElementID, $obElement = null)
{
return OfferItem::make($iElementID, $obElement);
}
}
Loading

0 comments on commit a589add

Please sign in to comment.