Skip to content

Commit

Permalink
Merge pull request #233 from oc-shopaholic/develop
Browse files Browse the repository at this point in the history
Release version 1.24.0
  • Loading branch information
kharanenka authored Dec 19, 2019
2 parents 5e8de09 + 5a2f641 commit 6422e21
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 79 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: ${{ secrets.Coveralls }}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Shopaholic

[![Build Status](https://travis-ci.org/lovata/oc-shopaholic-plugin.svg?branch=master)](https://travis-ci.org/lovata/oc-shopaholic-plugin)
[![Coverage Status](https://coveralls.io/repos/github/lovata/oc-shopaholic-plugin/badge.svg?branch=master)](https://coveralls.io/github/lovata/oc-shopaholic-plugin?branch=master)
[![Code Climate](https://codeclimate.com/github/lovata/oc-shopaholic-plugin/badges/gpa.svg)](https://codeclimate.com/github/lovata/oc-shopaholic-plugin)
[![Build Status](https://travis-ci.org/oc-shopaholic/oc-shopaholic-plugin.svg?branch=master)](https://travis-ci.org/oc-shopaholic/oc-shopaholic-plugin)
[![Coverage Status](https://coveralls.io/repos/github/oc-shopaholic/oc-shopaholic-plugin/badge.svg?branch=master)](https://coveralls.io/github/oc-shopaholic/oc-shopaholic-plugin?branch=master)
[![Maintainability](https://api.codeclimate.com/v1/badges/3d1cb11b6df3e444422f/maintainability)](https://codeclimate.com/github/oc-shopaholic/oc-shopaholic-plugin/maintainability)
[![Crowdin](https://d322cqt584bo4o.cloudfront.net/shopaholic-plugin-for-october/localized.svg)](https://crowdin.com/project/shopaholic-plugin-for-october)
[![SemVer](http://img.shields.io/SemVer/2.0.0.png)](http://semver.org/spec/v2.0.0.html)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
Expand Down
37 changes: 22 additions & 15 deletions classes/item/BrandItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
/**
* Class BrandItem
* @package Lovata\Shopaholic\Classes\Item
* @author Andrey Kharanenka, [email protected], LOVATA Group
* @author Andrey Kharanenka, [email protected], LOVATA Group
*
* @property int $id
* @property string $name
* @property string $slug
* @property string $code
* @property int $id
* @property string $name
* @property string $slug
* @property string $code
*
* @property string $preview_text
* @property \System\Models\File $preview_image
* @property string $preview_text
* @property \System\Models\File $preview_image
*
* @property string $description
* @property \October\Rain\Database\Collection|\System\Models\File[] $images
* @property string $description
* @property \October\Rain\Database\Collection|\System\Models\File[] $images
*/
class BrandItem extends ElementItem
{
Expand All @@ -34,13 +34,14 @@ class BrandItem extends ElementItem
* Returns URL of a brand page.
*
* @param string $sPageCode
* @param array $arRemoveParamList
*
* @return string
*/
public function getPageUrl($sPageCode = 'brand')
public function getPageUrl($sPageCode = 'brand', $arRemoveParamList = [])
{
//Get URL params
$arParamList = $this->getPageParamList($sPageCode);
$arParamList = $this->getPageParamList($sPageCode, $arRemoveParamList);

//Generate page URL
$sURL = CmsPage::url($sPageCode, $arParamList);
Expand All @@ -51,19 +52,25 @@ public function getPageUrl($sPageCode = 'brand')
/**
* Get URL param list by page code
* @param string $sPageCode
* @param array $arRemoveParamList
* @return array
*/
public function getPageParamList($sPageCode) : array
public function getPageParamList($sPageCode, $arRemoveParamList = []) : array
{
$arPageParamList = [];
$arResult = [];
if (!empty($arRemoveParamList)) {
foreach ($arRemoveParamList as $sParamName) {
$arResult[$sParamName] = null;
}
}

//Get URL params for page
$arParamList = PageHelper::instance()->getUrlParamList($sPageCode, 'BrandPage');
if (!empty($arParamList)) {
$sPageParam = array_shift($arParamList);
$arPageParamList[$sPageParam] = $this->slug;
$arResult[$sPageParam] = $this->slug;
}

return $arPageParamList;
return $arResult;
}
}
39 changes: 30 additions & 9 deletions classes/item/CategoryItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ public function clearProductCount()
* Returns URL of a category page.
*
* @param string $sPageCode
* @param array $arRemoveParamList
*
* @return string
*/
public function getPageUrl($sPageCode)
public function getPageUrl($sPageCode, $arRemoveParamList = [])
{
//Get URL params
$arParamList = $this->getPageParamList($sPageCode);
$arParamList = $this->getPageParamList($sPageCode, $arRemoveParamList);

//Generate page URL
$sURL = CmsPage::url($sPageCode, $arParamList);
Expand All @@ -116,29 +117,49 @@ public function getPageUrl($sPageCode)
/**
* Get URL param list by page code
* @param string $sPageCode
* @param array $arRemoveParamList
* @return array
*/
public function getPageParamList($sPageCode) : array
public function getPageParamList($sPageCode, $arRemoveParamList = []) : array
{
$arResult = [];
if (!empty($arRemoveParamList)) {
foreach ($arRemoveParamList as $sParamName) {
$arResult[$sParamName] = null;
}
}

//Get all slug params
$arParamList = PageHelper::instance()->getUrlParamList($sPageCode, null);
if (!empty($arParamList)) {
foreach ($arParamList as $sParamName) {
$arResult[$sParamName] = null;
}
}

//Get URL params for page
$arParamList = PageHelper::instance()->getUrlParamList($sPageCode, 'CategoryPage');
if (empty($arParamList)) {
return [];
}

$arParamList = array_reverse($arParamList);

//Get slug list
$arSlugList = $this->getSlugList();
$arSlugList = array_reverse($arSlugList);

$arWildcardParamList = PageHelper::instance()->getUrlParamList($sPageCode, 'CategoryPage', 'slug', true);
if (!empty($arWildcardParamList)) {
$arSlugList = array_reverse($arSlugList);
$arResult[array_shift($arWildcardParamList)] = implode('/', $arSlugList);

return $arResult;
}

//Prepare page property list
$arPagePropertyList = [];
foreach ($arParamList as $sParamName) {
$arPagePropertyList[$sParamName] = array_shift($arSlugList);
$arResult[$sParamName] = array_shift($arSlugList);
}

return $arPagePropertyList;
return $arResult;
}

/**
Expand Down
18 changes: 13 additions & 5 deletions classes/item/ProductItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ public function isActive()
* Returns URL of a category page.
*
* @param string $sPageCode
* @param array $arRemoveParamList
*
* @return string
*/
public function getPageUrl($sPageCode = 'product')
public function getPageUrl($sPageCode = 'product', $arRemoveParamList = [])
{
//Get URL params
$arParamList = $this->getPageParamList($sPageCode);
$arParamList = $this->getPageParamList($sPageCode, $arRemoveParamList);

//Generate page URL
$sURL = CmsPage::url($sPageCode, $arParamList);
Expand All @@ -138,11 +139,18 @@ public function getPageUrl($sPageCode = 'product')
/**
* Get URL param list by page code
* @param string $sPageCode
* @param array $arRemoveParamList
* @return array
*/
public function getPageParamList($sPageCode) : array
public function getPageParamList($sPageCode, $arRemoveParamList = []) : array
{
$arResult = [];
$arPageParamList = [];
if (!empty($arRemoveParamList)) {
foreach ($arRemoveParamList as $sParamName) {
$arResult[$sParamName] = null;
}
}

//Get URL params for categories
$aCategoryParamList = $this->category->getPageParamList($sPageCode);
Expand All @@ -155,9 +163,9 @@ public function getPageParamList($sPageCode) : array
$arPageParamList[$sPageParam] = $this->slug;
}

$arPageParamList = array_merge($aCategoryParamList, $aBrandParamList, $arPageParamList);
$arResult = array_merge($arResult, $aCategoryParamList, $aBrandParamList, $arPageParamList);

return $arPageParamList;
return $arResult;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions components/BrandData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
* Class BrandData
* @package Lovata\Shopaholic\Components
* @author Andrey Kharanenka, [email protected], LOVATA Group
*
* @link https://github.com/lovata/oc-shopaholic-plugin/wiki/BrandData
*/
class BrandData extends ElementData
{
Expand Down
3 changes: 1 addition & 2 deletions components/BrandList.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Class BrandList
* @package Lovata\Shopaholic\Components
* @author Andrey Kharanenka, [email protected], LOVATA Group
*
* @link https://github.com/lovata/oc-shopaholic-plugin/wiki/BrandList
*/
class BrandList extends ComponentBase
{
Expand Down Expand Up @@ -36,6 +34,7 @@ public function make($arElementIDList = null)

/**
* Method for ajax request with empty response
* @deprecated
* @return bool
*/
public function onAjaxRequest()
Expand Down
2 changes: 0 additions & 2 deletions components/BrandPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* Class BrandPage
* @package Lovata\Shopaholic\Components
* @author Andrey Kharanenka, [email protected], LOVATA Group
*
* @link https://github.com/lovata/oc-shopaholic-plugin/wiki/BrandPage
*/
class BrandPage extends ElementPage
{
Expand Down
2 changes: 0 additions & 2 deletions components/Breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
* @package Lovata\Shopaholic\Components
* @author Andrey Kharanenka, [email protected], LOVATA Group
* @deprecated
*
* @link https://github.com/lovata/oc-shopaholic-plugin/wiki/Breadcrumbs
*/
class Breadcrumbs extends ComponentBase
{
Expand Down
2 changes: 0 additions & 2 deletions components/CategoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
* Class CategoryData
* @package Lovata\Shopaholic\Components
* @author Andrey Kharanenka, [email protected], LOVATA Group
*
* @link https://github.com/lovata/oc-shopaholic-plugin/wiki/CategoryData
*/
class CategoryData extends ElementData
{
Expand Down
2 changes: 1 addition & 1 deletion components/CategoryList.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* Class CategoryList
* @package Lovata\Shopaholic\Components
* @author Andrey Kharanenka, [email protected], LOVATA Group
* @link https://github.com/lovata/oc-shopaholic-plugin/wiki/CategoryList
*/
class CategoryList extends ComponentBase
{
Expand Down Expand Up @@ -35,6 +34,7 @@ public function make($arElementIDList = null)

/**
* Method for ajax request with empty response
* @deprecated
* @return bool
*/
public function onAjaxRequest()
Expand Down
85 changes: 81 additions & 4 deletions components/CategoryPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
* Class CategoryPage
* @package Lovata\Shopaholic\Components
* @author Andrey Kharanenka, [email protected], LOVATA Group
*
* @link https://github.com/lovata/oc-shopaholic-plugin/wiki/CategoryPage
*/
class CategoryPage extends ElementPage
{
protected $bNeedSmartURLCheck = true;
protected $bHasWildCard = true;

/** @var \Lovata\Shopaholic\Models\Category */
protected $obElement;
Expand Down Expand Up @@ -45,6 +44,26 @@ protected function getElementObject($sElementSlug)
return null;
}

if (!$this->property('has_wildcard')) {
$obElement = $this->getElementBySlug($sElementSlug);
} else {
$obElement = $this->getElementByWildcard($sElementSlug);
}

if (!empty($obElement)) {
Event::fire('shopaholic.category.open', [$obElement]);
}

return $obElement;
}

/**
* Get category by default
* @param string $sElementSlug
* @return Category|null
*/
protected function getElementBySlug($sElementSlug)
{
if ($this->isSlugTranslatable()) {
$obElement = Category::active()->transWhere('slug', $sElementSlug)->first();
if (!$this->checkTransSlug($obElement, $sElementSlug)) {
Expand All @@ -53,8 +72,66 @@ protected function getElementObject($sElementSlug)
} else {
$obElement = Category::active()->getBySlug($sElementSlug)->first();
}
if (!empty($obElement)) {
Event::fire('shopaholic.category.open', [$obElement]);

return $obElement;
}

/**
* Get category by wildcard
* @param string $sElementSlug
* @return Category|null
*/
protected function getElementByWildcard($sElementSlug)
{
$arSlugList = explode('/', $sElementSlug);
if (empty($arSlugList)) {
return null;
}

$arSlugList = array_reverse($arSlugList);
$sElementSlug = array_shift($arSlugList);

$obElement = $this->getElementBySlug($sElementSlug);
if (empty($obElement)) {
return null;
}

if (empty($arSlugList) && empty($obElement->parent)) {
return $obElement;
}

$obNestingElement = $obElement;

foreach ($arSlugList as $sSlug) {
$obNestingElement = $this->getNestingElement($sSlug, $obNestingElement);
if (empty($obNestingElement)) {
return null;
}
}

if (!empty($obNestingElement->parent)) {
return null;
}

return $obElement;
}

/**
* Get nesting element
* @param string $sElementSlug
* @param Category $obNestingElement
* @return Category
*/
protected function getNestingElement($sElementSlug, $obNestingElement)
{
if (empty($obNestingElement) || empty($sElementSlug)) {
return null;
}

$obElement = $obNestingElement->parent;

if (empty($obElement) || $obElement->slug != $sElementSlug) {
return null;
}

return $obElement;
Expand Down
1 change: 1 addition & 0 deletions components/CurrencyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function switch($sCurrencyCode = null)

/**
* Method for ajax request with empty response
* @deprecated
* @return bool
*/
public function onAjaxRequest()
Expand Down
Loading

0 comments on commit 6422e21

Please sign in to comment.