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

Special Price condition not working for configurable products #51

Open
jaxtheking opened this issue Mar 16, 2020 · 1 comment
Open

Special Price condition not working for configurable products #51

jaxtheking opened this issue Mar 16, 2020 · 1 comment

Comments

@jaxtheking
Copy link

jaxtheking commented Mar 16, 2020

Running a clothing store, we exclusively use configurable products.
Price, special price and special from/to dates are all null on configurable products.

I've managed to get validation working correctly on configurable products which have a valid special price on at least one of its associated products (children).

Have I missed something?? If not, would you consider including the following code?

// SmartCategory/Model/Rule/Condition/Product/Sale.php

/**
 * Validate product attribute value for condition
 *
 * @param AbstractModel $model
 * @return bool
 */
public function validate(AbstractModel $model)
{
    $isOnSale = false;
    
    if ($model->getTypeId() == 'configurable') {
        $models = $model->getTypeInstance()->getUsedProducts($model);
        foreach ($models as $model) {
            if ($this->validateSingleProduct($model)) {
                return true;
            }
        }
        return false;
    } else {
        return $this->validateSingleProduct($model);
    }
}

public function validateSingleProduct(AbstractModel $model)
{
    $specialPrice = $model->getSpecialPrice();
    $isDateInterval = $this->_localeDate->isScopeDateInInterval(
        $model->getStore(),
        $model->getSpecialFromDate(),
        $model->getSpecialToDate()
    );

    if ($this->getOperator() == '==' && $specialPrice && $isDateInterval) {
        return true;
    } elseif ($this->getOperator() == '!=' && (!$specialPrice || !$isDateInterval)) {
        return true;
    }
    return false;
}

Thanks,
Luca

@karliuka
Copy link
Owner

Hi,
Thank you very much.
I will check it as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants