Skip to content

Commit 50ba63c

Browse files
Brandon BishopBrandon Bishop
authored andcommitted
Add product collections
1 parent fdfce6c commit 50ba63c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3708
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
.idea
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* @Author: Brandon van Rensburg
4+
* @Copyright: 2024 Deploy Ecommerce (https://www.deploy.co.uk/)
5+
* @Package: DeployEcommerce_BuilderIO
6+
*/
7+
8+
namespace DeployEcommerce\BuilderIO\Api\Data;
9+
10+
/**
11+
* Interface ProductCollectionInterface
12+
*
13+
* @api
14+
*/
15+
interface ProductCollectionInterface
16+
{
17+
const ID = 'id';
18+
const TYPE = 'type';
19+
const CONFIG = 'config';
20+
const PRODUCT_COUNT = 'product_count';
21+
const URL_KEY = 'url_key';
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace DeployEcommerce\BuilderIO\Api\Data;
4+
5+
interface ProductCollectionResultInterface
6+
{
7+
/**
8+
* @param int $collectionId
9+
* @return array
10+
*/
11+
public function getProductCollection(int $collectionId);
12+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* @Author: Brandon van Rensburg
4+
* @Copyright: 2024 Deploy Ecommerce (https://www.deploy.co.uk/)
5+
* @Package: DeployEcommerce_BuilderIO
6+
*/
7+
8+
namespace DeployEcommerce\BuilderIO\Api\Data;
9+
10+
use Magento\Framework\Api\SearchResultsInterface;
11+
12+
/**
13+
* Interface ProductCollectionSearchResultsInterface
14+
*
15+
* @api
16+
*/
17+
interface ProductCollectionSearchResultsInterface
18+
{
19+
/**
20+
* @return \Magento\Catalog\Api\Data\ProductInterface[]
21+
*/
22+
public function getProducts();
23+
24+
/**
25+
* @return int
26+
*/
27+
public function getCount();
28+
}

Api/ProductCollectionInterface.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
/**
3+
* @Author: Brandon van Rensburg
4+
* @Copyright: 2024 Deploy Ecommerce (https://www.deploy.co.uk/)
5+
* @Package: DeployEcommerce_BuilderIO
6+
*/
7+
8+
namespace DeployEcommerce\BuilderIO\Api;
9+
10+
/**
11+
* Interface ProductCollectionInterface
12+
*
13+
* @api
14+
*/
15+
interface ProductCollectionInterface {
16+
17+
const ID = "id";
18+
const TYPE = "type";
19+
20+
const TYPE_CONDITION = "condition";
21+
const TYPE_SKU = "sku";
22+
const TYPE_CATEGORY = "category";
23+
24+
const PRODUCT_COUNT = "product_count";
25+
const URL_KEY = "url_key";
26+
const CONFIG = "config";
27+
28+
public function getConditionsInstance();
29+
30+
public function getActionsInstance();
31+
32+
/**
33+
* @return mixed
34+
*/
35+
public function getId();
36+
37+
38+
/**
39+
* @param mixed $id
40+
* @return ProductCollection|AbstractModel
41+
*/
42+
public function setId($id);
43+
44+
45+
/**
46+
* @return mixed
47+
*/
48+
public function getType();
49+
50+
51+
/**
52+
* @param string $type
53+
* @return ProductCollectionInterface
54+
*/
55+
public function setType($type);
56+
57+
58+
/**
59+
* @return mixed
60+
*/
61+
public function getConfig();
62+
63+
64+
/**
65+
* @param string $config
66+
* @return ProductCollectionInterface
67+
*/
68+
public function setConfig($config);
69+
70+
71+
/**
72+
* @return mixed
73+
*/
74+
public function getProductCount();
75+
76+
77+
/**
78+
* @param int $productCount
79+
* @return ProductCollectionInterface
80+
*/
81+
public function setProductCount($productCount);
82+
83+
84+
/**
85+
* @return mixed
86+
*/
87+
public function getUrlKey();
88+
89+
90+
/**
91+
* @param string $urlKey
92+
* @return ProductCollectionInterface
93+
*/
94+
public function setUrlKey($urlKey);
95+
96+
97+
public function getProducts();
98+
99+
100+
public function getCount();
101+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* @Author: Brandon van Rensburg
4+
* @Copyright: 2024 Deploy Ecommerce (https://www.deploy.co.uk/)
5+
* @Package: DeployEcommerce_BuilderIO
6+
*/
7+
8+
namespace DeployEcommerce\BuilderIO\Api;
9+
use Magento\Framework\Api\SearchCriteriaInterface;
10+
11+
/**
12+
* @api
13+
*/
14+
interface ProductCollectionRepositoryInterface
15+
{
16+
/**
17+
* I need this to return products in json form
18+
*
19+
* @param int $id
20+
* @return \DeployEcommerce\BuilderIO\Api\Data\ProductCollectionSearchResultsInterface
21+
* @throws \Magento\Framework\Exception\NoSuchEntityException
22+
*/
23+
public function getById($id): ProductCollectionInterface;
24+
25+
/**
26+
* @param $productCollection
27+
* @return
28+
*/
29+
public function save($productCollection);
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
public function getList(SearchCriteriaInterface $searchCriteria);
35+
36+
/**
37+
* @inheritDoc
38+
*/
39+
public function delete($productCollection);
40+
41+
/**
42+
* @inheritDoc
43+
*/
44+
public function deleteById($id);
45+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* @Author: Brandon van Rensburg
4+
* @Copyright: 2025 DeployEcommerce (https://www.techarlie.co.za/)
5+
* @Package: DeployEcommerce_BuilderIO
6+
*/
7+
namespace DeployEcommerce\BuilderIO\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Class BackButton
13+
*/
14+
class BackButton extends GenericButton implements ButtonProviderInterface
15+
{
16+
/**
17+
* @return array
18+
*/
19+
public function getButtonData()
20+
{
21+
return [
22+
'label' => __('Back'),
23+
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
24+
'class' => 'back',
25+
'sort_order' => 10
26+
];
27+
}
28+
29+
/**
30+
* @return string
31+
*/
32+
public function getBackUrl()
33+
{
34+
return $this->getUrl('*/*/');
35+
}
36+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* @Author: Brandon van Rensburg
4+
* @Copyright: 2025 DeployEcommerce (https://www.techarlie.co.za/)
5+
* @Package: DeployEcommerce_BuilderIO
6+
*/
7+
namespace DeployEcommerce\BuilderIO\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Class DeleteButton
13+
*/
14+
class DeleteButton extends GenericButton implements ButtonProviderInterface
15+
{
16+
/**
17+
* @return array
18+
*/
19+
public function getButtonData()
20+
{
21+
$data = [];
22+
if ($this->getId()) {
23+
$data = [
24+
'label' => __('Delete'),
25+
'class' => 'delete',
26+
'on_click' => 'deleteConfirm(\'' . __(
27+
'Are you sure you want to do this?'
28+
) . '\', \'' . $this->getDeleteUrl() . '\', {"data": {}})',
29+
'sort_order' => 20,
30+
];
31+
}
32+
return $data;
33+
}
34+
35+
/**
36+
* URL to send delete requests to.
37+
*
38+
* @return string
39+
*/
40+
public function getDeleteUrl()
41+
{
42+
return $this->getUrl('*/*/delete', ['id' => $this->getId()]);
43+
}
44+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* @Author: Brandon van Rensburg
4+
* @Copyright: 2025 DeployEcommerce (https://www.techarlie.co.za/)
5+
* @Package: DeployEcommerce_BuilderIO
6+
*/
7+
8+
namespace DeployEcommerce\BuilderIO\Block\Adminhtml\Edit;
9+
10+
use Magento\Backend\Block\Widget\Context;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use DeployEcommerce\BuilderIO\Api\ProductCollectionRepositoryInterface;
13+
14+
class GenericButton
15+
{
16+
/**
17+
* @var \Magento\Backend\Block\Widget\Context
18+
*/
19+
protected $context;
20+
21+
/**
22+
* @var \DeployEcommerce\BuilderIO\Api\ProductCollectionRepositoryInterface
23+
*/
24+
protected $productCollectionRepository;
25+
26+
/**
27+
* @param \Magento\Backend\Block\Widget\Context $context
28+
* @param \DeployEcommerce\BuilderIO\Api\ProductCollectionRepositoryInterface $productCollectionRepository
29+
*/
30+
public function __construct(
31+
Context $context,
32+
ProductCollectionRepositoryInterface $productCollectionRepository
33+
) {
34+
$this->context = $context;
35+
$this->productCollectionRepository = $productCollectionRepository;
36+
}
37+
38+
/**
39+
* @return int|null
40+
*/
41+
public function getId()
42+
{
43+
try {
44+
return $this->productCollectionRepository->getById(
45+
$this->context->getRequest()->getParam('id')
46+
)->getId();
47+
} catch (NoSuchEntityException $e) {
48+
}
49+
return null;
50+
}
51+
52+
/**
53+
* @param string $route
54+
* @param array $params
55+
* @return string
56+
*/
57+
public function getUrl($route = '', $params = [])
58+
{
59+
return $this->context->getUrlBuilder()->getUrl($route, $params);
60+
}
61+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* @Author: Brandon van Rensburg
4+
* @Copyright: 2025 DeployEcommerce (https://www.techarlie.co.za/)
5+
* @Package: DeployEcommerce_BuilderIO
6+
*/
7+
namespace DeployEcommerce\BuilderIO\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
/**
12+
* Class ResetButton
13+
*/
14+
class ResetButton extends GenericButton implements ButtonProviderInterface
15+
{
16+
/**
17+
* @return array
18+
*/
19+
public function getButtonData()
20+
{
21+
return [
22+
'label' => __('Reset'),
23+
'class' => 'reset',
24+
'on_click' => 'location.reload();',
25+
'sort_order' => 30
26+
];
27+
}
28+
}

0 commit comments

Comments
 (0)