Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/Ecombricks/InventorySales/Plugin/Block/Adminhtml/Order/Create/Items/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/Ecombricks/InventorySales/Plugin/Block/Adminhtml/Order/Create/Items/Grid.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Ecombricks\InventorySales\Plugin\Block\Adminhtml\Order\Create\Items;

/**
 * Create order items grid plugin
 */
class Grid
{
    
    /**
     * Stock state
     * 
     * @var \Ecombricks\InventoryCatalogInventory\Api\StockStateInterface
     */
    protected $stockState;
    
    /**
     * Constructor
     * 
     * @param \Ecombricks\InventoryCatalogInventory\Api\StockStateInterface $stockState
     * @return void
     */
    public function __construct(
        \Ecombricks\InventoryCatalogInventory\Api\StockStateInterface $stockState
    )
    {
        $this->stockState = $stockState;
    }
    
    /**
     * Get quote item product IDs
     * 
     * @return array
     */
    protected function getQuoteItemProductIds($item)
    {
        $productIds = [];
        $childItems = $item->getChildren();
        if (count($childItems)) {
            foreach ($childItems as $childItem) {
                $productIds[] = $childItem->getProduct()->getId();
            }
        } else {
            $productIds[] = $item->getProduct()->getId();
        }
        return $productIds;
    }
    
    /**
     * Around get items
     * 
     * @param \Magento\Sales\Block\Adminhtml\Order\Create\Items\Grid $subject
     * @param \Closure $proceed
     * @return \Magento\Quote\Model\Quote\Item[]
     */
    public function aroundGetItems(
        \Magento\Sales\Block\Adminhtml\Order\Create\Items\Grid $subject,
        \Closure $proceed
    )
    {
        $items = $subject->getParentBlock()->getItems();
        $quote = $subject->getQuote();
        $oldSuperMode = $quote->getIsSuperMode();
        $quote->setIsSuperMode(false);
        foreach ($items as $item) {
            $product = $item->getProduct();
            $sourceCode = $item->getSourceCode();
            $qty = $item->getQty();
            $item->setQty($qty);
            if (!$item->getMessage()) {
                foreach ($this->getQuoteItemProductIds($item) as $productId) {
                    $check = $this->stockState->checkQuoteItemSourceQty($productId, $sourceCode, $qty, $qty, $qty);
                    $item->setMessage($check->getMessage());
                    $item->setHasError($check->getHasError());
                }
            }
            if ($product->getStatus() == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED) {
                $item->setMessage($this->escapeHtml(__('This product is disabled.')));
                $item->setHasError(true);
            }
        }
        $quote->setIsSuperMode($oldSuperMode);
        return $items; 
    }
    
}

Spamworldpro Mini