Skip to content

Commit 68c6ee5

Browse files
committed
🎨 adds plan action and bootstraps to default store to handle plans
1 parent 4704493 commit 68c6ee5

File tree

5 files changed

+99
-136
lines changed

5 files changed

+99
-136
lines changed

‎Controller/Adminhtml/Plans/Create.php

100644100755
+3-30
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,12 @@
22

33
namespace MundiPagg\MundiPagg\Controller\Adminhtml\Plans;
44

5-
use Magento\Backend\App\Action;
6-
use Magento\Backend\App\Action\Context;
7-
use Magento\Framework\Registry;
8-
use Magento\Framework\View\Result\PageFactory;
5+
use MundiPagg\MundiPagg\Controller\Adminhtml\Plans\PlanAction;
96
use Mundipagg\Core\Recurrence\Aggregates\Plan;
10-
use Mundipagg\Core\Recurrence\Repositories\PlanRepository;
117
use Mundipagg\Core\Recurrence\Services\PlanService;
128

13-
class Create extends Action
9+
class Create extends PlanAction
1410
{
15-
protected $resultPageFactory = false;
16-
/**
17-
* @var ProductsPlanFactory
18-
*/
19-
private $productsPlanFactory;
20-
21-
/**
22-
* Constructor
23-
*
24-
* @param Context $context
25-
* @param PageFactory $resultPageFactory
26-
* @param Registry $coreRegistry
27-
*/
28-
public function __construct(
29-
Context $context,
30-
PageFactory $resultPageFactory,
31-
Registry $coreRegistry
32-
) {
33-
parent::__construct($context);
34-
$this->resultPageFactory = $resultPageFactory;
35-
$this->coreRegistry = $coreRegistry;
36-
}
37-
3811
/**
3912
* Index action
4013
*
@@ -43,7 +16,7 @@ public function __construct(
4316
public function execute()
4417
{
4518
$planId = (int) $this->getRequest()->getParam('id');
46-
if($planId) {
19+
if ($planId) {
4720
//@todo this should be a product plan core object
4821
$planService = new PlanService();
4922
$planData = $planService->findById($planId);

‎Controller/Adminhtml/Plans/Delete.php

100644100755
+2-38
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,11 @@
22

33
namespace MundiPagg\MundiPagg\Controller\Adminhtml\Plans;
44

5-
use Magento\Backend\App\Action;
6-
use Magento\Backend\App\Action\Context;
7-
use Magento\Framework\Message\Factory;
8-
use Magento\Framework\Registry;
9-
use Magento\Framework\View\Result\PageFactory;
5+
use MundiPagg\MundiPagg\Controller\Adminhtml\Plans\PlanAction;
106
use Mundipagg\Core\Recurrence\Services\PlanService;
11-
use Mundipagg\Core\Recurrence\Services\ProductSubscriptionService;
12-
use MundiPagg\MundiPagg\Concrete\Magento2CoreSetup;
13-
use MundiPagg\MundiPagg\Model\ProductsSubscriptionFactory;
147

15-
class Delete extends Action
8+
class Delete extends PlanAction
169
{
17-
protected $resultPageFactory;
18-
19-
/**
20-
* @var Registry
21-
*/
22-
protected $coreRegistry;
23-
24-
/**
25-
* Constructor
26-
*
27-
* @param \Magento\Backend\App\Action\Context $context
28-
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
29-
* @throws \Exception
30-
*/
31-
public function __construct(
32-
\Magento\Backend\App\Action\Context $context,
33-
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
34-
Registry $coreRegistry,
35-
Factory $messageFactory
36-
)
37-
{
38-
$this->resultPageFactory = $resultPageFactory;
39-
$this->coreRegistry = $coreRegistry;
40-
$this->messageFactory = $messageFactory;
41-
Magento2CoreSetup::bootstrap();
42-
43-
parent::__construct($context);
44-
}
45-
4610
/**
4711
* Index action
4812
*

‎Controller/Adminhtml/Plans/Index.php

100644100755
+3-21
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,10 @@
22

33
namespace MundiPagg\MundiPagg\Controller\Adminhtml\Plans;
44

5-
use Magento\Backend\App\Action;
6-
use Magento\Backend\App\Action\Context;
7-
use Magento\Framework\View\Result\PageFactory;
5+
use MundiPagg\MundiPagg\Controller\Adminhtml\Plans\PlanAction;
86

9-
class Index extends Action
7+
class Index extends PlanAction
108
{
11-
protected $resultPageFactory = false;
12-
13-
/**
14-
* Constructor
15-
*
16-
* @param Context $context
17-
* @param PageFactory $resultPageFactory
18-
*/
19-
public function __construct(
20-
Context $context,
21-
PageFactory $resultPageFactory
22-
) {
23-
$this->resultPageFactory = $resultPageFactory;
24-
parent::__construct($context);
25-
}
26-
279
/**
2810
* Index action
2911
*
@@ -33,7 +15,7 @@ public function execute()
3315
{
3416
$resultPage = $this->resultPageFactory->create();
3517
$resultPage->getConfig()->getTitle()->prepend(__("Plans"));
36-
18+
3719
return $resultPage;
3820
}
3921
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace MundiPagg\MundiPagg\Controller\Adminhtml\Plans;
4+
5+
use Magento\Backend\App\Action;
6+
use Magento\Backend\App\Action\Context;
7+
use Magento\Framework\Registry;
8+
use Magento\Framework\View\Result\PageFactory;
9+
use Magento\Framework\Controller\Result\JsonFactory;
10+
use MundiPagg\MundiPagg\Concrete\Magento2CoreSetup;
11+
use Magento\Framework\Message\Factory;
12+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
13+
use MundiPagg\MundiPagg\Helper\ProductHelper;
14+
use Magento\Store\Model\StoreManagerInterface;
15+
16+
class PlanAction extends Action
17+
{
18+
19+
protected $resultPageFactory = false;
20+
/**
21+
* @var CollectionFactory
22+
*/
23+
protected $productCollectionFactory;
24+
/**
25+
* @var JsonFactory
26+
*/
27+
protected $resultJsonFactory;
28+
/**
29+
* @var ProductHelper
30+
*/
31+
protected $productHelper;
32+
/**
33+
* @var Registry
34+
*/
35+
protected $coreRegistry;
36+
/**
37+
* @var Factory
38+
*/
39+
protected $messageFactory;
40+
41+
42+
/**
43+
* Constructor
44+
*
45+
* @param Context $context
46+
* @param PageFactory $resultPageFactory
47+
* @param Registry $coreRegistry
48+
*/
49+
public function __construct(
50+
Context $context,
51+
PageFactory $resultPageFactory,
52+
Registry $coreRegistry,
53+
Factory $messageFactory,
54+
CollectionFactory $productCollectionFactory,
55+
JsonFactory $resultJsonFactory,
56+
ProductHelper $productHelper,
57+
StoreManagerInterface $storeManager
58+
) {
59+
parent::__construct($context);
60+
61+
$this->resultPageFactory = $resultPageFactory;
62+
$this->coreRegistry = $coreRegistry;
63+
$this->messageFactory = $messageFactory;
64+
$this->productHelper = $productHelper;
65+
$this->productCollectionFactory = $productCollectionFactory;
66+
$this->resultJsonFactory = $resultJsonFactory;
67+
$this->storeManager = $storeManager;
68+
69+
$this->bootstrapDefaultStoreConfigurations();
70+
}
71+
72+
/**
73+
* @return \Magento\Framework\Controller\ResultInterface
74+
*/
75+
public function execute()
76+
{
77+
}
78+
79+
private function bootstrapDefaultStoreConfigurations()
80+
{
81+
$defaultStoreId = Magento2CoreSetup::getDefaultStoreId();
82+
$this->storeManager->setCurrentStore($defaultStoreId);
83+
84+
Magento2CoreSetup::bootstrap();
85+
}
86+
}

‎Controller/Adminhtml/Plans/SearchProduct.php

100644100755
+5-47
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,17 @@
22

33
namespace MundiPagg\MundiPagg\Controller\Adminhtml\Plans;
44

5-
use Magento\Backend\App\Action;
6-
use Magento\Backend\App\Action\Context;
7-
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
5+
6+
use MundiPagg\MundiPagg\Controller\Adminhtml\Plans\PlanAction;
87
use Magento\Framework\App\ObjectManager;
9-
use Magento\Framework\Controller\Result\JsonFactory;
10-
use Magento\Framework\View\Result\PageFactory;
118
use Mundipagg\Core\Kernel\Services\MoneyService;
129
use Mundipagg\Core\Recurrence\Aggregates\Plan;
1310
use Mundipagg\Core\Recurrence\Aggregates\ProductSubscription;
1411
use Mundipagg\Core\Recurrence\Services\PlanService;
1512
use Mundipagg\Core\Recurrence\Services\ProductSubscriptionService;
16-
use MundiPagg\MundiPagg\Concrete\Magento2CoreSetup;
17-
use MundiPagg\MundiPagg\Helper\ProductHelper;
1813

19-
class SearchProduct extends Action
14+
class SearchProduct extends PlanAction
2015
{
21-
protected $resultPageFactory = false;
22-
/**
23-
* @var CollectionFactory
24-
*/
25-
protected $productCollectionFactory;
26-
/**
27-
* @var JsonFactory
28-
*/
29-
protected $resultJsonFactory;
30-
/**
31-
* @var ProductHelper
32-
*/
33-
protected $productHelper;
34-
35-
/**
36-
* Constructor
37-
*
38-
* @param Context $context
39-
* @param PageFactory $resultPageFactory
40-
* @param CollectionFactory $productCollectionFactory
41-
* @param JsonFactory $resultJsonFactory
42-
*/
43-
public function __construct(
44-
Context $context,
45-
PageFactory $resultPageFactory,
46-
CollectionFactory $productCollectionFactory,
47-
JsonFactory $resultJsonFactory,
48-
ProductHelper $productHelper
49-
) {
50-
parent::__construct($context);
51-
$this->resultPageFactory = $resultPageFactory;
52-
$this->productCollectionFactory = $productCollectionFactory;
53-
$this->resultJsonFactory = $resultJsonFactory;
54-
$this->productHelper = $productHelper;
55-
Magento2CoreSetup::bootstrap();
56-
}
57-
5816
/**
5917
* Index action
6018
*
@@ -72,7 +30,7 @@ public function execute()
7230
$product = $objectManager->get('\Magento\Catalog\Model\Product')
7331
->load($productId);
7432

75-
if (empty($product) ) {
33+
if (empty($product)) {
7634
return;
7735
}
7836

@@ -229,4 +187,4 @@ public function getRecurrenceService($recurrenceType)
229187
}
230188
return new ProductSubscriptionService();
231189
}
232-
}
190+
}

0 commit comments

Comments
 (0)