Bug in ShoppingCartManager.GetShoppingCartItemWarnings()

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
For version 1.70, there is a bug in the ShoppingCartManager class in method GetShoppingCartItemWarnings() at line #729. The else on this line causes the available end date to not be tested if the available start date has a value.

Therefore, if a customer already has a product variant in their cart before the variant's available end date, then they can purchase the product variant after the variant's available end date (if the variant has a value set for the available start date). A customer can also move the product from their wishlist to their shopping cart and complete a purchase after the variant's available end date. Though, in either case, after the product is purchased, the product's Published status changes to false.

To reproduce this bug, set valid dates for a product variant's available start (today - 2 days) and end (today + 2 days) dates. Add the product variant to the cart. Change the end date (to yesterday) so that the product is no longer available (verify by visiting the product details page and the product variant should not be visible). Return to the shopping cart summary page and complete the checkout; there is no error displayed although the product isn't available for purchase.

current code (code to remove underlined):
if (productVariant.AvailableStartDateTime.HasValue)
{
    DateTime _now = DateTime.UtcNow;
    DateTime _availableStartDateTime = DateTime.SpecifyKind(productVariant.AvailableStartDateTime.Value, DateTimeKind.Utc);
    if (_availableStartDateTime.CompareTo(_now) > 0)
    {
        warnings.Add("Product is not available");
    }
}
else if (productVariant.AvailableEndDateTime.HasValue)
{
    DateTime _now = DateTime.UtcNow;
    DateTime _availableEndDateTime = DateTime.SpecifyKind(productVariant.AvailableEndDateTime.Value, DateTimeKind.Utc);
    if (_availableEndDateTime.CompareTo(_now) < 0)
    {
        warnings.Add("Product is not available");
    }
}

change to the following (new code underlined):
bool availableStartDateError = false;
if (productVariant.AvailableStartDateTime.HasValue)
{
    DateTime _now = DateTime.UtcNow;
    DateTime _availableStartDateTime = DateTime.SpecifyKind(productVariant.AvailableStartDateTime.Value, DateTimeKind.Utc);
    if (_availableStartDateTime.CompareTo(_now) > 0)
    {
        warnings.Add("Product is not available");
        availableStartDateError = true;
    }
}
if (productVariant.AvailableEndDateTime.HasValue && !availableStartDateError)
{
    DateTime _now = DateTime.UtcNow;
    DateTime _availableEndDateTime = DateTime.SpecifyKind(productVariant.AvailableEndDateTime.Value, DateTimeKind.Utc);
    if (_availableEndDateTime.CompareTo(_now) < 0)
    {
        warnings.Add("Product is not available");
    }
}

The Boolean was added in case both the start and end dates are invalid so that the error message "Product is not available" isn't displayed twice. This can occur because the start date can be set to after the end date (another bug?).

.
13 years ago
Thanks a lot.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.