Skip to content

Special price vigency for configurable childs (simple products associated) doesn´t work #7362

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

Closed
valenciaisaza opened this issue Nov 8, 2016 · 8 comments
Labels
bug report Component: Catalog Fixed in 2.1.x The issue has been fixed in 2.1 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@valenciaisaza
Copy link

Special price vigency for configurable child´s (simple products associated) doesn´t work

Preconditions

  1. Magento 2.1.2
  2. PHP 7.0.11

Steps to reproduce

  1. Create configurable product (I created a color-configurable).
  2. Create his childs with different colors.
  3. Assign a Special price for one of teh simple´s, with the lower price of all.
  4. Put the vigency with both dates in past.

Expected result

  1. The Configurable price in the catalog and the product page is the lowest actual price (having the validity in consideration)

Actual result

  1. Shown the special price expired (because is the lowest)
    image
@valenciaisaza
Copy link
Author

valenciaisaza commented Nov 9, 2016

I don´t know if it helps

Searching in the code I found that in the \Magento\Catalog\Pricing\Price\SpecialPrice Class when the method "isScopeDateInInterval" is called by a simple product, the product has the Special price dates. But when the same method is called for a simple child of a configurable product, the product don't have this dates, so tha validation fails

    public function isScopeDateInInterval()
    {
        return $this->localeDate->isScopeDateInInterval(
            $this->product->getStore(),
            $this->getSpecialFromDate(),
            $this->getSpecialToDate()
        );
    }

@valenciaisaza
Copy link
Author

I´m here one more time

I found the problem in this class: vendor\magento\module-configurable-product\Pricing\Price\ConfigurableOptionsProvider.php

In the method "getProducts"

Original method

public function getProducts(ProductInterface $product)
    {
        if (!isset($this->products[$product->getId()])) {
            if ($this->requestSafety->isSafeMethod()) {
                $productIds = $this->resource->getConnection()->fetchCol(
                    '(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
                );

                $this->products[$product->getId()] = $this->collectionFactory->create()
                    ->addAttributeToSelect(['price', 'special_price'])
                    ->addIdFilter($productIds);
            } else {
                $this->products[$product->getId()] = $this->configurable->getUsedProducts($product);
            }
        }
        return $this->products[$product->getId()];
    }

Modified method

public function getProducts(ProductInterface $product)
    {
        if (!isset($this->products[$product->getId()])) {
            if ($this->requestSafety->isSafeMethod()) {
                $productIds = $this->resource->getConnection()->fetchCol(
                    '(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
                );

                $this->products[$product->getId()] = $this->collectionFactory->create()
                    ->addAttributeToSelect(['price', 'special_price', 'special_from_date', 'special_to_date'])
                    ->addIdFilter($productIds);
            } else {
                $this->products[$product->getId()] = $this->configurable->getUsedProducts($product);
            }
        }
        return $this->products[$product->getId()];
    }

Obviously I will create a module with a plugin o something like that, while magento apply the fix to the vendor

@cuiyang000
Copy link

@valenciaisaza wish I could find this issue earlier... After more than 7h digging, I came out with the same solution as you.

The issue for me is that even if all the sub-products' special price expired or haven't started yet, the main product still shown as having special price, and if you choose the option in the product detail page, the special price would change to regular one. So put it simple, the special from&to dates were not taken into account at all when displaying main product.

@olysenko olysenko self-assigned this Dec 13, 2016
@olysenko
Copy link

Hi, thank you for your report. We already have internal issue MAGETWO-52577

@olysenko olysenko added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development and removed in progress labels Dec 13, 2016
@olysenko olysenko removed their assignment Dec 13, 2016
@mauromm
Copy link

mauromm commented Dec 27, 2016

In Magento 2.1.3, the method getProducts() was moved to Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProvider

To patch it, you need to implement di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProvider"
                type="YourVendor\YourModuleFixSpecialPrice\Pricing\Price\LowestPriceOptionsProvider" />
</config>

And replace:

  public function getProducts(ProductInterface $product)
   {
       $productIds = $this->resource->getConnection()->fetchCol(
           '(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
       );

       $lowestPriceChildProducts = $this->collectionFactory->create()
           ->addAttributeToSelect(['price', 'special_price','special_from_date', 'special_to_date'])
           ->addIdFilter($productIds)
           ->getItems();
       return $lowestPriceChildProducts;
   }

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-70491

@magento-engcom-team magento-engcom-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Catalog Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed labels Sep 11, 2017
@magento-engcom-team
Copy link
Contributor

@valenciaisaza, thank you for your report.
The issue is already fixed in 2.2.0

@magento-engcom-team
Copy link
Contributor

Hi @valenciaisaza. Thank you for your report.
The issue has been fixed in #13490 by @simpleadm in 2.1-develop branch
Related commit(s):

The fix will be available with the upcoming 2.1.13 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.1.x The issue has been fixed in 2.1 release line label Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Fixed in 2.1.x The issue has been fixed in 2.1 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests

7 participants