Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface to di.xml in issue23717 #23753

Merged

Conversation

edenduong
Copy link
Contributor

Description (*)

No Preference for Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface in di.xml
Solution: Just add to di.xml

Fixed Issues (if relevant)

  1. dependency injection fails for \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface #23717: dependency injection fails for \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface

Manual testing scenarios (*)

  1. Create a new module and a class
  2. Add in the constructor the \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface
    e.g.

   public function __construct(
        ProductRepositoryInterface $productRepository,
        CategoryRepositoryInterface $categoryRepository,
        LoggerInterface $logger,
        SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
        CollectionFactory $collectionFactory,
        Product $productModel,
        Data $helper,
        \Magento\Framework\Filesystem\DirectoryList $directoryList,
        StoreManagerInterface $storeManager,
        \Magento\ConfigurableProduct\Model\Product\Type\Configurable $configurableType,
        State $state,
        PriceResolverInterface $configurableRegularPrice
    )

Result :The dependency is injected correctly

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jul 18, 2019

Hi @edenduong. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-5462 has been created to process this Pull Request
✳️ @ihor-sviziev, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@ihor-sviziev ihor-sviziev added the Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests label Jul 18, 2019
@engcom-Alfa engcom-Alfa self-assigned this Jul 18, 2019
@orlangur
Copy link
Contributor

@edenduong @ihor-sviziev is it not used in core?

@edenduong
Copy link
Contributor Author

edenduong commented Jul 18, 2019

Hi Orlangur, @orlangur

Currently, the interface isn't injected to any class. But I think it is better if we add it in the di.xml and other modules can use the interface instead of the model PriceResolver (following to the Service Contract https://devdocs.magento.com/guides/v2.3/extension-dev-guide/service-contracts/service-contracts.html)

@edenduong
Copy link
Contributor Author

And if we use the class: Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver to other module, it don't think it can run. Because no preference but now it call the function of the inferface:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\ConfigurableProduct\Pricing\Price;

use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Pricing\PriceCurrencyInterface;

class ConfigurablePriceResolver implements PriceResolverInterface
{
    /**
     * @var \Magento\ConfigurableProduct\Pricing\Price\PriceResolverInterface
     */
    protected $priceResolver;

    /**
     * @var PriceCurrencyInterface
     * @deprecated 100.1.1
     */
    protected $priceCurrency;

    /**
     * @var Configurable
     * @deprecated 100.1.1
     */
    protected $configurable;

    /**
     * @var LowestPriceOptionsProviderInterface
     */
    private $lowestPriceOptionsProvider;

    /**
     * @param PriceResolverInterface $priceResolver
     * @param Configurable $configurable
     * @param PriceCurrencyInterface $priceCurrency
     * @param LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider
     */
    public function __construct(
        PriceResolverInterface $priceResolver,
        Configurable $configurable,
        PriceCurrencyInterface $priceCurrency,
        LowestPriceOptionsProviderInterface $lowestPriceOptionsProvider = null
    ) {
        $this->priceResolver = $priceResolver;
        $this->configurable = $configurable;
        $this->priceCurrency = $priceCurrency;
        $this->lowestPriceOptionsProvider = $lowestPriceOptionsProvider ?:
            ObjectManager::getInstance()->get(LowestPriceOptionsProviderInterface::class);
    }

    /**
     * @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
     * @return float
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
    {
        $price = null;

        foreach ($this->lowestPriceOptionsProvider->getProducts($product) as $subProduct) {
            $productPrice = $this->priceResolver->resolvePrice($subProduct);
            $price = isset($price) ? min($price, $productPrice) : $productPrice;
        }

        return (float)$price;
    }
}

@orlangur
Copy link
Contributor

@edenduong thanks, that's what I was thinking about - it was injected by a concrete implementation and not by interface :(

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

@m2-assistant
Copy link

m2-assistant bot commented Jul 23, 2019

Hi @edenduong, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

magento-engcom-team pushed a commit that referenced this pull request Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants