init
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Checkout\Block\Cart\Item\Bundle;
|
||||
|
||||
use Magento\Bundle\Helper\Catalog\Product\Configuration;
|
||||
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\Data\CollectionFactory;
|
||||
use Magento\Framework\Pricing\PriceCurrencyInterface;
|
||||
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel;
|
||||
|
||||
class Renderer extends \Stemcell\Checkout\Block\Cart\Item\Renderer
|
||||
{
|
||||
/**
|
||||
* Bundle catalog product configuration
|
||||
*
|
||||
* @var Configuration
|
||||
*/
|
||||
protected Configuration $_bundleProductConfiguration;
|
||||
|
||||
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,
|
||||
Configuration $bundleProductConfiguration,
|
||||
array $data = [],
|
||||
ItemResolverInterface $itemResolver = null
|
||||
) {
|
||||
$this->_bundleProductConfiguration = $bundleProductConfiguration;
|
||||
parent::__construct(
|
||||
$context,
|
||||
$productConfig,
|
||||
$checkoutSession,
|
||||
$imageBuilder,
|
||||
$urlHelper,
|
||||
$messageManager,
|
||||
$priceCurrency,
|
||||
$moduleManager,
|
||||
$messageInterpretationStrategy,
|
||||
$labCollection,
|
||||
$salespersonCollection,
|
||||
$baseCollectionFactory,
|
||||
$customerSession,
|
||||
$data,
|
||||
$itemResolver
|
||||
);
|
||||
}
|
||||
|
||||
public function getOptionList()
|
||||
{
|
||||
return $this->_bundleProductConfiguration->getOptions($this->getItem());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return cart item error messages
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
$messages = [];
|
||||
$quoteItem = $this->getItem();
|
||||
|
||||
// Add basic messages occurring during this page load
|
||||
$baseMessages = $quoteItem->getMessage(false);
|
||||
if ($baseMessages) {
|
||||
foreach ($baseMessages as $message) {
|
||||
$messages[] = ['text' => $message, 'type' => $quoteItem->getHasError() ? 'error' : 'notice'];
|
||||
}
|
||||
}
|
||||
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Checkout\Block\Cart\Item\Renderer;
|
||||
|
||||
use Stemcell\Checkout\Block\Cart\Item\Renderer;
|
||||
use Magento\Framework\DataObject\IdentityInterface;
|
||||
|
||||
class Configurable extends Renderer implements IdentityInterface
|
||||
{
|
||||
/**
|
||||
* Path in config to the setting which defines if parent or child product should be used to generate a thumbnail.
|
||||
* @deprecated moved to model because of class refactoring
|
||||
* @see \Magento\ConfigurableProduct\Model\Product\Configuration\Item\ItemProductResolver::CONFIG_THUMBNAIL_SOURCE
|
||||
*/
|
||||
const CONFIG_THUMBNAIL_SOURCE = 'checkout/cart/configurable_product_image';
|
||||
|
||||
/**
|
||||
* Get item configurable child product
|
||||
*
|
||||
* @return \Magento\Catalog\Model\Product|null
|
||||
*/
|
||||
public function getChildProduct()
|
||||
{
|
||||
if ($option = $this->getItem()->getOptionByCode('simple_product')) {
|
||||
return $option->getProduct();
|
||||
}
|
||||
return $this->getProduct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item product name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getProductName()
|
||||
{
|
||||
if ($option = $this->getItem()->getOptionByCode('simple_product')) {
|
||||
return $option->getProduct()->getName();
|
||||
}
|
||||
return $this->getProduct()->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of all options for product
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptionList()
|
||||
{
|
||||
return $this->_productConfig->getOptions($this->getItem());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return identifiers for produced content
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIdentities()
|
||||
{
|
||||
$identities = parent::getIdentities();
|
||||
if ($this->getItem()) {
|
||||
$identities = array_merge($identities, $this->getChildProduct()->getIdentities());
|
||||
}
|
||||
return $identities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get price for exact simple product added to cart
|
||||
*
|
||||
* @inheritdoc
|
||||
* @since 100.3.1
|
||||
*/
|
||||
public function getProductPriceHtml(\Magento\Catalog\Model\Product $product)
|
||||
{
|
||||
return parent::getProductPriceHtml($this->getChildProduct());
|
||||
}
|
||||
}
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user