1

In this Model they had mentioned the getTypeId() but for what they mentioned as type id i can't understand can anyone please explain me.

$orderItem->getProduct()->getTypeId()

what will be the result in this TypeId().

Folder Path : /var/www/html/development/amt/vendor/magento/module-inventory-shipping-admin-ui/Model

<?php
    /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    declare(strict_types=1);

    namespace Magento\InventoryShippingAdminUi\Model;

    use Magento\InventorySalesApi\Model\GetSkuFromOrderItemInterface;
    use Magento\InventoryApi\Api\Data\StockInterface;
    use Magento\InventoryApi\Api\StockRepositoryInterface;
    use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface;
    use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface;
    use Magento\Sales\Api\Data\OrderInterface;

    /**
     * Is source inventory of certain order is manageable
     */
    class IsOrderSourceManageable
    {
        /**
         * @var GetSkuFromOrderItemInterface
         */
        private $getSkuFromOrderItem;

        /**
         * @var GetStockItemConfigurationInterface
         */
        private $getStockItemConfiguration;

        /**
         * @var StockRepositoryInterface
         */
        private $stockRepository;

        /**
         * @var IsSourceItemManagementAllowedForProductTypeInterface
         */
        private $isSourceItemManagementAllowedForProductType;

        /**
         * @param GetSkuFromOrderItemInterface $productRepository
         * @param GetStockItemConfigurationInterface $getStockItemConfiguration
         * @param StockRepositoryInterface $stockRepository
         * @param IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
         */
        public function __construct(
            GetSkuFromOrderItemInterface $productRepository,
            GetStockItemConfigurationInterface $getStockItemConfiguration,
            StockRepositoryInterface $stockRepository,
            IsSourceItemManagementAllowedForProductTypeInterface $isSourceItemManagementAllowedForProductType
        ) {
            $this->getSkuFromOrderItem = $productRepository;
            $this->getStockItemConfiguration = $getStockItemConfiguration;
            $this->stockRepository = $stockRepository;
            $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType;
        }

        /**
         * Check if source manageable for certain order
         *
         * @param OrderInterface $order
         * @return bool
         */
        public function execute(OrderInterface $order): bool
        {
            $stocks = $this->stockRepository->getList()->getItems();
            $orderItems = $order->getItems();
            foreach ($orderItems as $orderItem) {
                $productType = $orderItem->getProduct()->getTypeId();
                if (!$this->isSourceItemManagementAllowedForProductType->execute($productType)) {
                    continue;
                }

                /** @var StockInterface $stock */
                foreach ($stocks as $stock) {
                    $inventoryConfiguration = $this->getStockItemConfiguration->execute(
                        $this->getSkuFromOrderItem->execute($orderItem),
                        $stock->getStockId()
                    );

                    if ($inventoryConfiguration->isManageStock()) {
                        return true;
                    }
                }
            }

            return false;
        }
    }
| improve this question | | | | |
2

It's returning the product type: simple, configurable, virtual, etc

| improve this answer | | | | |
  • 1
    Thank you for your response bro – Sabareesh Apr 29 at 6:26
0

The Type Id refers to the type of products in the order.

/vendor/magento/module-catalog/Api/Data/ProductInterface.php:169

For each order item it could be set to any of the following product types, plus any custom product types that have been added to your build.

\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE = 'simple'
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE = 'simple'
\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE = 'configurable'
\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE = 'bundle'
\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE = 'grouped'
\Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL = 'virtual'
\Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE = 'downloadable'

If that product type does not allow stock management, it will skip the checks

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.