init
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Checkout\Block\Cart\Item;
|
||||
|
||||
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\Data\Collection;
|
||||
use Magento\Framework\Data\CollectionFactory;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Pricing\PriceCurrencyInterface;
|
||||
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
|
||||
use Stemcell\Customer\Model\Lab;
|
||||
use Stemcell\Customer\Model\LabFactory;
|
||||
use Stemcell\Customer\Model\LabRepository;
|
||||
use Stemcell\Customer\Model\Salesperson;
|
||||
use Stemcell\Customer\Model\ResourceModel;
|
||||
use Stemcell\Customer\Model\SalespersonRepository;
|
||||
|
||||
class Renderer extends \Magento\Checkout\Block\Cart\Item\Renderer
|
||||
{
|
||||
protected ResourceModel\Lab\Collection $labCollection;
|
||||
protected ResourceModel\Salesperson\Collection $salespersonCollection;
|
||||
|
||||
protected Session $customerSession;
|
||||
|
||||
protected CollectionFactory $baseCollectionFactory;
|
||||
|
||||
protected ?Lab $lab = null;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\View\Element\Template\Context $context
|
||||
* @param \Magento\Catalog\Helper\Product\Configuration $productConfig
|
||||
* @param \Magento\Checkout\Model\Session $checkoutSession
|
||||
* @param \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder
|
||||
* @param \Magento\Framework\Url\Helper\Data $urlHelper
|
||||
* @param \Magento\Framework\Message\ManagerInterface $messageManager
|
||||
* @param PriceCurrencyInterface $priceCurrency
|
||||
* @param \Magento\Framework\Module\Manager $moduleManager
|
||||
* @param InterpretationStrategyInterface $messageInterpretationStrategy
|
||||
* @param ResourceModel\Lab\Collection $labCollection
|
||||
* @param ResourceModel\Salesperson\Collection $salespersonCollection
|
||||
* @param array $data
|
||||
* @param ItemResolverInterface|null $itemResolver
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\View\Element\Template\Context $context,
|
||||
\Magento\Catalog\Helper\Product\Configuration $productConfig,
|
||||
\Magento\Checkout\Model\Session $checkoutSession,
|
||||
\Magento\Catalog\Block\Product\ImageBuilder $imageBuilder,
|
||||
\Magento\Framework\Url\Helper\Data $urlHelper,
|
||||
\Magento\Framework\Message\ManagerInterface $messageManager,
|
||||
PriceCurrencyInterface $priceCurrency,
|
||||
\Magento\Framework\Module\Manager $moduleManager,
|
||||
InterpretationStrategyInterface $messageInterpretationStrategy,
|
||||
ResourceModel\Lab\Collection $labCollection,
|
||||
ResourceModel\Salesperson\Collection $salespersonCollection,
|
||||
CollectionFactory $baseCollectionFactory,
|
||||
Session $customerSession,
|
||||
array $data = [],
|
||||
ItemResolverInterface $itemResolver = null
|
||||
)
|
||||
{
|
||||
parent::__construct(
|
||||
$context,
|
||||
$productConfig,
|
||||
$checkoutSession,
|
||||
$imageBuilder,
|
||||
$urlHelper,
|
||||
$messageManager,
|
||||
$priceCurrency,
|
||||
$moduleManager,
|
||||
$messageInterpretationStrategy,
|
||||
$data,
|
||||
$itemResolver
|
||||
);
|
||||
$this->customerSession = $customerSession;
|
||||
$this->baseCollectionFactory = $baseCollectionFactory;
|
||||
$this->labCollection = $labCollection;
|
||||
$this->salespersonCollection = $salespersonCollection;
|
||||
}
|
||||
|
||||
public function getLabs(): Collection|ResourceModel\Lab\Collection
|
||||
{
|
||||
if ($this->customerSession->getCustomerId()) {
|
||||
$this->labCollection->addFieldToFilter('main_table.customer_id', $this->customerSession->getCustomerId())
|
||||
->getSelect()
|
||||
->joinLeft('salesperson', 'salesperson.salesperson_id=main_table.salesperson_id', ['salesperson'=>'salesperson.name']);
|
||||
return $this->labCollection;
|
||||
}
|
||||
|
||||
return $this->baseCollectionFactory->create()->setItemObjectClass(Lab::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Stemcell\Customer\Api\Data\LabInterface|Lab
|
||||
*/
|
||||
public function getLab()
|
||||
{
|
||||
try {
|
||||
if ($labId = $this->_item->getData('lab_id')) {
|
||||
/* @var $labRepository LabRepository */
|
||||
$labRepository = \Magento\Framework\App\ObjectManager::getInstance()->get(LabRepository::class);
|
||||
/* @var $salespersonRepository SalespersonRepository */
|
||||
$salespersonRepository = \Magento\Framework\App\ObjectManager::getInstance()->get(SalespersonRepository::class);
|
||||
$this->lab = $labRepository->get($labId);
|
||||
$salesperson = $salespersonRepository->get($this->lab->getSalespersonId());
|
||||
$this->lab->setData('salesperson', $salesperson->getName());
|
||||
return $this->lab;
|
||||
}
|
||||
} catch (LocalizedException $e) {
|
||||
}
|
||||
/* @var $labFactory LabFactory */
|
||||
$labFactory = \Magento\Framework\App\ObjectManager::getInstance()->get(LabFactory::class);
|
||||
return $labFactory->create();
|
||||
}
|
||||
|
||||
public function getSalesperson() {
|
||||
if ($this->customerSession->getCustomerId()) {
|
||||
$this->salespersonCollection->addFieldToFilter('customer_id', $this->customerSession->getCustomerId());
|
||||
return $this->salespersonCollection;
|
||||
}
|
||||
|
||||
return $this->baseCollectionFactory->create()->setItemObjectClass(Salesperson::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user