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/InventoryInventorySales/Plugin/StockState/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/Ecombricks/InventoryInventorySales/Plugin/StockState/CheckQuoteItemQtyPlugin.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See LICENSE.txt for license details.
 */
declare(strict_types=1);

namespace Ecombricks\InventoryInventorySales\Plugin\StockState;

/**
 * Check quote item qty plugin
 */
class CheckQuoteItemQtyPlugin
{
    
    /**
     * Product management
     * 
     * @var \Ecombricks\InventoryInventoryCatalog\Model\ProductManagement
     */
    protected $productManagement;
    
    /**
     * Object factory
     * 
     * @var \Magento\Framework\DataObject\Factory
     */
    protected $objectFactory;
    
    /**
     * Format
     * 
     * @var \Magento\Framework\Locale\FormatInterface
     */
    protected $format;
    
    /**
     * Is product salable for requested qty
     * 
     * @var \Ecombricks\InventoryInventorySales\Api\IsProductSalableForRequestedQtyInterface
     */
    protected $isProductSalableForRequestedQty;
    
    /**
     * Back order notify customer condition
     * 
     * @var \Ecombricks\InventoryInventorySales\Model\IsProductSalableForRequestedQtyCondition\BackOrderNotifyCustomerCondition
     */
    protected $backOrderNotifyCustomerCondition;
    
    /**
     * Product metadata
     * 
     * @var \Magento\Framework\App\ProductMetadata 
     */
    protected $productMetadata;
    
    /**
     * Constructor
     * 
     * @param \Ecombricks\InventoryInventoryCatalog\Model\ProductManagement $productManagement
     * @param \Magento\Framework\DataObject\Factory $objectFactory
     * @param \Magento\Framework\Locale\FormatInterface $format
     * @param \Ecombricks\InventoryInventorySales\Api\IsProductSalableForRequestedQtyInterface $isProductSalableForRequestedQty
     * @param \Ecombricks\InventoryInventorySales\Model\IsProductSalableForRequestedQtyCondition\BackOrderNotifyCustomerCondition $backOrderNotifyCustomerCondition
     * @param \Magento\Framework\App\ProductMetadata $productMetadata
     * @return void
     */
    public function __construct(
        \Ecombricks\InventoryInventoryCatalog\Model\ProductManagement $productManagement,
        \Magento\Framework\DataObject\Factory $objectFactory,
        \Magento\Framework\Locale\FormatInterface $format,
        \Ecombricks\InventoryInventorySales\Api\IsProductSalableForRequestedQtyInterface $isProductSalableForRequestedQty,
        \Ecombricks\InventoryInventorySales\Model\IsProductSalableForRequestedQtyCondition\BackOrderNotifyCustomerCondition $backOrderNotifyCustomerCondition,
        \Magento\Framework\App\ProductMetadata $productMetadata
    )
    {
        $this->productManagement = $productManagement;
        $this->objectFactory = $objectFactory;
        $this->format = $format;
        $this->isProductSalableForRequestedQty = $isProductSalableForRequestedQty;
        $this->backOrderNotifyCustomerCondition = $backOrderNotifyCustomerCondition;
        $this->productMetadata = $productMetadata;
    }
    
    /**
     * Get number
     *
     * @param string|float|int|null $qty
     *
     * @return float|null
     */
    protected function getNumber($qty)
    {
        if (is_numeric($qty)) {
            return $qty;
        }
        return $this->format->getNumber($qty);
    }
    
    /**
     * Around check quote item source qty
     *
     * @param \Magento\CatalogInventory\Api\StockStateInterface $subject
     * @param \Closure $proceed
     * @param int $productId
     * @param string $sourceCode
     * @param float $itemQty
     * @param float $qtyToCheck
     * @param float $origQty
     * @return \Magento\Framework\DataObject
     * @throws \Magento\Framework\Exception\LocalizedException
     * @throws \Magento\Framework\Exception\NoSuchEntityException
     */
    public function aroundCheckQuoteItemSourceQty(
        \Magento\CatalogInventory\Api\StockStateInterface $subject,
        \Closure $proceed,
        $productId,
        $sourceCode,
        $itemQty,
        $qtyToCheck,
        $origQty
    )
    {
        $result = $this->objectFactory->create();
        $result->setHasError(false);
        $qty = max($this->getNumber($itemQty), $this->getNumber($qtyToCheck));
        $sku = $this->productManagement->getSku((int) $productId);
        $isSalableResult = $this->isProductSalableForRequestedQty->execute($sku, (string) $sourceCode, $qty);
        if ($isSalableResult->isSalable() === false) {
            foreach ($isSalableResult->getErrors() as $error) {
                $errorMessage = $error->getMessage();
                $result
                    ->setHasError(true)
                    ->setMessage($errorMessage)
                    ->setQuoteMessage($errorMessage)
                    ->setQuoteMessageIndex('qty');
            }
        } else {
            $productSalableResult = $this->backOrderNotifyCustomerCondition->execute($sku, (string) $sourceCode, $qty);
            if ($productSalableResult->getErrors()) {
                foreach ($productSalableResult->getErrors() as $error) {
                    $result->setMessage($error->getMessage());
                }
            }
        }
        return $result;
    }

}

Spamworldpro Mini