Skip to content

Commit

Permalink
Merge branch '1.1'
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
  • Loading branch information
jsirish committed Oct 30, 2023
2 parents 4d5cc40 + ad29db6 commit 16c4eb3
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 12 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [1.1.1](https://github.com/dynamic/silverstripe-products/tree/1.1.1) (2019-12-17)

[Full Changelog](https://github.com/dynamic/silverstripe-products/compare/1.1.0...1.1.1)

**Fixed bugs:**

- CRITICAL BUG ProductCategory::getProductList\(\) doesn't check permissions [\#27](https://github.com/dynamic/silverstripe-products/issues/27)

**Merged pull requests:**

- BUGFIX check permissions before returning product list [\#28](https://github.com/dynamic/silverstripe-products/pull/28) ([muskie9](https://github.com/muskie9))

## [1.1.0](https://github.com/dynamic/silverstripe-products/tree/1.1.0) (2019-12-11)

[Full Changelog](https://github.com/dynamic/silverstripe-products/compare/1.0.1...1.1.0)
Expand All @@ -8,6 +20,10 @@

- ENHANCEMENT allow for videos in the product "Images" [\#25](https://github.com/dynamic/silverstripe-products/issues/25)

**Merged pull requests:**

- ENHANCEMENT allow for Videos in product Images zone [\#26](https://github.com/dynamic/silverstripe-products/pull/26) ([muskie9](https://github.com/muskie9))

## [1.0.1](https://github.com/dynamic/silverstripe-products/tree/1.0.1) (2019-11-12)

[Full Changelog](https://github.com/dynamic/silverstripe-products/compare/1.0.0...1.0.1)
Expand Down
7 changes: 1 addition & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,5 @@
"process-timeout": 600
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
}
"prefer-stable": true
}
49 changes: 44 additions & 5 deletions src/Page/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@

class Product extends \Page
{
/**
* @var
*/
private $image;

/**
* @var
*/
private $has_images;

/**
* @var string
*/
Expand Down Expand Up @@ -125,17 +135,26 @@ public function getCMSFields()
return parent::getCMSFields();
}

/**
* @return bool
*/
public function setImage()
{
if ($this->getHasImages()) {
$this->image = $this->Images()->sort('SortOrder')->first();
}
return $this;
}

/**
* @return mixed
*/
public function getImage()
{
if ($this->Images()->exists()) {
$image = $this->Images()->sort('SortOrder')->first();
return $image;
if (!$this->image) {
$this->setImage();
}

return false;
return $this->image;
}

/**
Expand All @@ -151,4 +170,24 @@ public function getThumbnail()

return false;
}

/**
* @return $this
*/
public function setHasImages()
{
$this->has_images = $this->Images()->exists();
return $this;
}

/**
* @return mixed
*/
public function getHasImages()
{
if (!$this->has_images) {
$this->setHasImages();
}
return $this->has_images;
}
}
7 changes: 7 additions & 0 deletions src/Page/ProductCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace Dynamic\Products\Page;

use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\NumericField;
use SilverStripe\Security\Security;

class ProductCategory extends \Page
{
Expand Down Expand Up @@ -67,6 +70,10 @@ public function getProductList()

$this->extend('updateProductList', $products, $categories);

$products = $products->filterByCallback(function ($page) {
return $page->canView(Security::getCurrentUser());
});

return $products;
}
}
28 changes: 28 additions & 0 deletions tests/Page/ProductCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Dynamic\Products\Page\ProductCategory;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\FieldList;
use SilverStripe\Security\Member;

class ProductCategoryTest extends SapphireTest
{
Expand All @@ -22,4 +23,31 @@ public function testGetCMSFields()
$fields = $object->getCMSFields();
$this->assertInstanceOf(FieldList::class, $fields);
}

/**
*
*/
public function testGetProductList()
{
$this->markTestSkipped('Currently doesn\'t seem to respect the groups/members in automated tests');

$this->logOut();
$member = $this->objFromFixture(Member::class, 'author');
$this->logInAs(Member::get()->byID($member->ID));
$categoryID = $this->objFromFixture(ProductCategory::class, 'restricted')->ID;
/** @var ProductCategory $category */
$category = ProductCategory::get()->byID($categoryID);

$this->assertEquals(2, $category->getProductList()->count());

$this->logOut();
$member = $this->objFromFixture(Member::class, 'default');
$this->logInAs(Member::get()->byID($member->ID));
/** @var ProductCategory $category */
$category = ProductCategory::get()->byID($categoryID);

$this->assertEquals(1, $category->getProductList()->count());

$this->logOut();
}
}
15 changes: 14 additions & 1 deletion tests/fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,26 @@ Dynamic\Products\Model\Brochure:
Dynamic\Products\Page\ProductCategory:
default:
Title: 'Default Category'
restricted:
Title: 'Restricted Children'
CanViewType: 'Inherit'

Dynamic\Products\Page\Product:
one:
Title: 'Product One'
Brochures: =>Dynamic\Products\Model\Brochure.one
restrictedproduct:
Title: 'Restricted Product'
CanViewType: 'OnlyTheseUsers'
ViewerGroups: =>SilverStripe\Security\Group.content_authors
Parent: =>Dynamic\Products\Page\ProductCategory.restricted
nonrestrictedproduct:
Title: 'Non Restricted Product'
Parent: =>Dynamic\Products\Page\ProductCategory.restricted
CanViewType: 'Inherit'


Dynamic\Products\Page\ProductFileCollection:
default:
Title: 'Brochures'
ManagedClass: 'Dynamic\Products\Model\Brochure'
ManagedClass: 'Dynamic\Products\Model\Brochure'

0 comments on commit 16c4eb3

Please sign in to comment.