Skip to content

Commit

Permalink
WIP Remove ServiceContainer from src
Browse files Browse the repository at this point in the history
  • Loading branch information
tkcreateit committed Apr 24, 2024
1 parent edf74a0 commit 2ef1b57
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 126 deletions.
10 changes: 4 additions & 6 deletions src/Controller/Admin/ArticleAdministration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@
use OxidEsales\Eshop\Application\Model\Country as EShopCountry;
use OxidEsales\Eshop\Core\Field;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EVatModule\Model\ArticleVATGroupsList;
use OxidEsales\EVatModule\Model\CountryVATGroupsList;
use OxidEsales\EVatModule\Shop\Article;
use OxidEsales\EVatModule\Shop\Country;
use OxidEsales\EVatModule\Traits\ServiceContainer;
use OxidEsales\Facts\Facts;

/**
* Class responsible for TBE service administration.
*/
class ArticleAdministration extends AdminDetailsController
{
use ServiceContainer;

/** @var array Used to cache VAT Groups data. */
private $_aArticleVATGroupData = null;

Expand Down Expand Up @@ -55,7 +53,7 @@ public function save()
$request = Registry::getRequest();
$aParams = $request->getRequestParameter('editval');
$aVATGroupsParams = $request->getRequestParameter('VATGroupsByCountry');
$articleVATGroupsList = $this->getServiceFromContainer(ArticleVATGroupsList::class);
$articleVATGroupsList = ContainerFacade::get(ArticleVATGroupsList::class);
$articleVATGroupsList->setId($sCurrentArticleId);
$articleVATGroupsList->setData($aVATGroupsParams);
$articleVATGroupsList->save();
Expand All @@ -75,7 +73,7 @@ public function save()
*/
public function isSelected($sCountryId, $sVATGroupId)
{
$articleVATGroupsList = $this->getServiceFromContainer(ArticleVATGroupsList::class);
$articleVATGroupsList = ContainerFacade::get(ArticleVATGroupsList::class);
$articleVATGroupsList->load($this->getEditObjectId());
if (is_null($this->_aArticleVATGroupData)) {
$this->_aArticleVATGroupData = $articleVATGroupsList->getData();
Expand All @@ -98,7 +96,7 @@ public function getCountryAndVATGroupsData()
/** @var EShopCountry|Country $oCountry */
$oCountry = oxNew(EShopCountry::class);
$aViewData = array();
$oCountryVATGroupsList = $this->getServiceFromContainer(CountryVATGroupsList::class);
$oCountryVATGroupsList = ContainerFacade::get(CountryVATGroupsList::class);
$aVATGroupList = $oCountryVATGroupsList->getList();
foreach ($aVATGroupList as $sCountryId => $aGroupsList) {
$oCountry->load($sCountryId);
Expand Down
7 changes: 2 additions & 5 deletions src/Controller/Admin/ArticleExtendAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
namespace OxidEsales\EVatModule\Controller\Admin;

use OxidEsales\Eshop\Application\Model\Category as EShopCategory;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EVatModule\Model\CategoryArticlesUpdater;
use OxidEsales\EVatModule\Shop\Category;
use OxidEsales\EVatModule\Traits\ServiceContainer;

/**
* Adds additional functionality needed for oeVATTBE module when managing articles.
*/
class ArticleExtendAjax extends ArticleExtendAjax_parent
{
use ServiceContainer;

/**
* Adds article to category
* Creates new list
Expand All @@ -42,8 +40,7 @@ protected function populateOeVATTBEConfiguration($sCategoryId)
$oCategory = oxNew(EShopCategory::class);
$oCategory->load($sCategoryId);
if ($oCategory->isOeVATTBETBE()) {
$this
->getServiceFromContainer(CategoryArticlesUpdater::class)
ContainerFacade::get(CategoryArticlesUpdater::class)
->addCategoryTBEInformationToArticles($oCategory);
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/Controller/Admin/ArticleMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
namespace OxidEsales\EVatModule\Controller\Admin;

use OxidEsales\Eshop\Application\Model\Category as EShopCategory;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EVatModule\Model\CategoryArticlesUpdater;
use OxidEsales\EVatModule\Shop\Category;
use OxidEsales\EVatModule\Traits\ServiceContainer;

/**
* Adds additional functionality needed for oeVATTBE module when managing articles.
*/
class ArticleMain extends ArticleMain_parent
{
use ServiceContainer;

/**
* Add article to category.
*
Expand All @@ -41,8 +39,7 @@ protected function populateOeVATTBEConfiguration($sCategoryId)
$oCategory = oxNew(EShopCategory::class);
$oCategory->load($sCategoryId);
if ($oCategory->isOeVATTBETBE()) {
$this
->getServiceFromContainer(CategoryArticlesUpdater::class)
ContainerFacade::get(CategoryArticlesUpdater::class)
->addCategoryTBEInformationToArticles($oCategory);
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/Controller/Admin/CategoryAdministration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@
use OxidEsales\Eshop\Application\Model\Country;
use OxidEsales\Eshop\Core\Field;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EVatModule\Model\CategoryArticlesUpdater;
use OxidEsales\EVatModule\Model\CategoryVATGroupsList;
use OxidEsales\EVatModule\Model\CountryVATGroupsList;
use OxidEsales\EVatModule\Traits\ServiceContainer;

/**
* Class responsible for TBE services administration using categories.
*/
class CategoryAdministration extends AdminDetailsController
{
use ServiceContainer;

/** @var array Used to cache VAT Groups data. */
private $_aCategoryVATGroupData = null;

Expand All @@ -49,7 +47,7 @@ public function save()
$request = Registry::getRequest();
$aParams = $request->getRequestParameter('editval');
$aVATGroupsParams = $request->getRequestParameter('VATGroupsByCountry');
$oCategoryVATGroupsList = $this->getServiceFromContainer(CategoryVATGroupsList::class);
$oCategoryVATGroupsList = ContainerFacade::get(CategoryVATGroupsList::class);
$oCategoryVATGroupsList->setId($sCurrentCategoryId);
$oCategoryVATGroupsList->setData($aVATGroupsParams);
$oCategoryVATGroupsList->save();
Expand All @@ -60,8 +58,7 @@ public function save()
$oCategory->oxcategories__oevattbe_istbe = new Field($aParams['oevattbe_istbe']);
$oCategory->save();

$this
->getServiceFromContainer(CategoryArticlesUpdater::class)
ContainerFacade::get(CategoryArticlesUpdater::class)
->addCategoryTBEInformationToArticles($oCategory);
}

Expand All @@ -75,7 +72,7 @@ public function save()
*/
public function isSelected($sCountryId, $sVATGroupId)
{
$oCategoryVATGroupsList = $this->getServiceFromContainer(CategoryVATGroupsList::class);
$oCategoryVATGroupsList = ContainerFacade::get(CategoryVATGroupsList::class);
$oCategoryVATGroupsList->load($this->getEditObjectId());
if (is_null($this->_aCategoryVATGroupData)) {
$this->_aCategoryVATGroupData = $oCategoryVATGroupsList->getData();
Expand All @@ -98,7 +95,7 @@ public function getCountryAndVATGroupsData()
/** @var Country $country */
$country = oxNew(Country::class);
$aViewData = array();
$countryVATGroupsList = $this->getServiceFromContainer(CountryVATGroupsList::class);
$countryVATGroupsList = ContainerFacade::get(CountryVATGroupsList::class);
$aVATGroupList = $countryVATGroupsList->getList();
foreach ($aVATGroupList as $sCountryId => $aGroupsList) {
$country->load($sCountryId);
Expand Down
10 changes: 3 additions & 7 deletions src/Controller/Admin/CategoryMainAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@

use OxidEsales\Eshop\Application\Model\Category as EShopCategory;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EVatModule\Model\CategoryArticlesUpdater;
use OxidEsales\EVatModule\Shop\Category;
use OxidEsales\EVatModule\Traits\ServiceContainer;

/**
* Adds additional functionality needed for oeVATTBE module when managing articles.
*/
class CategoryMainAjax extends CategoryMainAjax_parent
{
use ServiceContainer;

/**
* Adds article to category.
* Creates new list.
Expand All @@ -40,8 +38,7 @@ public function removeArticle()
$aArticles = $this->getAll($this->addFilter("select $sArticleTable.oxid " . $this->getQuery()));
}

$this
->getServiceFromContainer(CategoryArticlesUpdater::class)
ContainerFacade::get(CategoryArticlesUpdater::class)
->removeCategoryTBEInformationFromArticles($aArticles);

parent::removeArticle();
Expand All @@ -57,8 +54,7 @@ protected function populateOeVATTBEConfiguration()
$oCategory = oxNew(EShopCategory::class);
$oCategory->load($sCategoryId);
if ($oCategory->isOeVATTBETBE()) {
$this
->getServiceFromContainer(CategoryArticlesUpdater::class)
ContainerFacade::get(CategoryArticlesUpdater::class)
->addCategoryTBEInformationToArticles($oCategory);
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/Controller/Admin/CountryVatGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
use OxidEsales\Eshop\Core\Language;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\UtilsView;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EVatModule\Model\CountryVATGroup;
use OxidEsales\EVatModule\Model\CountryVATGroupsList;
use OxidEsales\EVatModule\Traits\ServiceContainer;

/**
* Display VAT groups for particular country.
*/
class CountryVatGroups extends AdminDetailsController
{
use ServiceContainer;

/**
* To set only one error message in session.
*
Expand All @@ -48,8 +46,7 @@ public function render()
*/
public function getVatGroups()
{
return $this
->getServiceFromContainer(CountryVATGroupsList::class)
return ContainerFacade::get(CountryVATGroupsList::class)
->load($this->getEditObjectId());
}

Expand All @@ -71,7 +68,7 @@ public function addCountryVATGroup()
return null;
}

$oGroup = $this->getServiceFromContainer(CountryVATGroup::class);
$oGroup = ContainerFacade::get(CountryVATGroup::class);
$oGroup->setCountryId($sCountryId);
$oGroup->setName($sGroupName);
$oGroup->setRate($fVATRate);
Expand All @@ -88,7 +85,7 @@ public function changeCountryVATGroups()
{
$aVatGroups = Registry::getRequest()->getRequestParameter('updateval');

$oVatGroup = $this->getServiceFromContainer(CountryVATGroup::class);
$oVatGroup = ContainerFacade::get(CountryVATGroup::class);
foreach ($aVatGroups as $aVatGroup) {
if (!$aVatGroup['oevattbe_id'] || !$aVatGroup['oevattbe_name']) {
if (!$this->_blMissingParameterErrorSet) {
Expand All @@ -112,7 +109,7 @@ public function deleteCountryVatGroup()
{
$iVATGroupId = Registry::getRequest()->getRequestParameter('countryVATGroupId');

$oVATGroup = $this->getServiceFromContainer(CountryVATGroup::class);
$oVATGroup = ContainerFacade::get(CountryVATGroup::class);
$oVATGroup->setId($iVATGroupId);
$oVATGroup->delete();

Expand Down
6 changes: 2 additions & 4 deletions src/Controller/Admin/OrderMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
namespace OxidEsales\EVatModule\Controller\Admin;

use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EVatModule\Model\OrderEvidenceList;
use OxidEsales\EVatModule\Traits\ServiceContainer;

/**
* Adds additional functionality needed for oeVATTBE module when managing orders.
*/
class OrderMain extends OrderMain_parent
{
use ServiceContainer;

/**
* Returns template name from parent and sets values for template.
*
Expand All @@ -30,7 +28,7 @@ public function render()
$order = oxNew(Order::class);
$sOrderEvidenceId = $this->getOeVATTBECurrentOrderEvidenceId($order, $sOrderId);

$oEvidenceList = $this->getServiceFromContainer(OrderEvidenceList::class);
$oEvidenceList = ContainerFacade::get(OrderEvidenceList::class);
$oEvidenceList->loadWithCountryNames($sOrderId);
$aEvidencesData = $oEvidenceList->getData();

Expand Down
17 changes: 6 additions & 11 deletions src/Controller/BasketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@
use OxidEsales\Eshop\Application\Model\BasketItem;
use OxidEsales\Eshop\Application\Model\Shop as EShopShop;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EVatModule\Model\BasketVATValidator;
use OxidEsales\EVatModule\Model\User;
use OxidEsales\EVatModule\Service\BasketItemsValidator;
use OxidEsales\EVatModule\Shop\Basket;
use OxidEsales\EVatModule\Shop\Shop;
use OxidEsales\EVatModule\Traits\ServiceContainer;

/**
* Hooks to basket class to get events.
*/
class BasketController extends BasketController_parent
{
use ServiceContainer;

/**
* Executes parent::render(), creates list with basket articles
* Returns name of template file basket::_sThisTemplate (for Search
Expand All @@ -33,12 +31,11 @@ class BasketController extends BasketController_parent
*/
public function render()
{
$oUserCountry = $this->getServiceFromContainer(User::class);
$oUserCountry = ContainerFacade::get(User::class);
$oBasket = Registry::getSession()->getBasket();
if ($this->getUser() && !$oUserCountry->isUserFromDomesticCountry() && $oBasket) {
/** @var BasketItemsValidator $oVATTBEBasketItemsValidator */
$this
->getServiceFromContainer(BasketItemsValidator::class)
ContainerFacade::get(BasketItemsValidator::class)
->validateTbeArticlesAndShowMessageIfNeeded('basket');
}

Expand Down Expand Up @@ -74,7 +71,7 @@ public function oeVATTBEShowVATTBEMarkMessage()
/** @var EShopBasket|Basket $oBasket */
$oBasket = Registry::getSession()->getBasket();
$oCountry = $oBasket->getOeVATTBECountry();
$oTBEUserCountry = $this->getServiceFromContainer(User::class);
$oTBEUserCountry = ContainerFacade::get(User::class);

$blBasketValid = $oBasket->hasOeTBEVATArticles();
$blCountryAppliesTBEVAT = !$oCountry || $oCountry->appliesOeTBEVATTbeVat();
Expand All @@ -91,8 +88,7 @@ public function oeVATTBEShowVATTBEMarkMessage()
*/
public function isOeVATTBETBEArticleValid($oBasketItem)
{
return $this
->getServiceFromContainer(BasketVATValidator::class)
return ContainerFacade::get(BasketVATValidator::class)
->isArticleValid($oBasketItem);
}

Expand All @@ -105,8 +101,7 @@ public function isOeVATTBETBEArticleValid($oBasketItem)
*/
public function oeVATTBEShowVATTBEMark($oBasketItem)
{
return $this
->getServiceFromContainer(BasketVATValidator::class)
return ContainerFacade::get(BasketVATValidator::class)
->showVATTBEMark($oBasketItem);
}

Expand Down
Loading

0 comments on commit 2ef1b57

Please sign in to comment.