Jump to content

Refreshing cart price after adding a specific price rule and a specific price


bollydow

Recommended Posts

The problem is that despite the addition of a specific price and a rule for a given product at the time of adding a product to the Cart, the changed price in the Cart appears only after several dozen seconds.

 

I overwritten CartController.php in the following way:

===============

class CartController extends CartControllerCore
{
    public function __construct()
    {
            $this->context = Context::getContext();
            $this->bootstrap = true;
            parent::__construct();
    }

    public static function slugify($text)
    {
      $text = preg_replace('~[^\pL\d]+~u', '-', $text); // replace non letter or digits by -
      $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); // transliterate
      $text = preg_replace('~[^-\w]+~', '', $text); // remove unwanted characters
      $text = trim($text, '-'); // trim
      $text = preg_replace('~-+~', '-', $text); // remove duplicate -
      $text = strtolower($text); // lowercase
      if (empty($text)) {
        return 'n-a';
      }
      return $text;
    }

    public function initContent()
    {
        // parent::initContent();

        if ( isset($_COOKIE['price']) && isset($_COOKIE['quantity']) && $_COOKIE['store_name'])
        {
            if ( $this->id_product && $this->context->cart->id && ( Tools::getIsset('add') || Tools::getIsset('update') ) )
            {                
                //SpecificPriceRule()
                // $cart->updateQty(1, $product_id, $product->getDefaultAttribute($product->id));
                $specific_price_rule = new SpecificPriceRule();
                $specific_price_rule->name = self::slugify($_COOKIE['store_name'])."-" .$this->id_product."-".$_COOKIE['price'];
                $specific_price_rule->id_shop = $this->context->shop->id;
                $specific_price_rule->id_currency = $this->context->currency->id;
                $specific_price_rule->id_country = $this->context->country->id;
                $specific_price_rule->id_group = $this->context->customer->id_default_group;
                $specific_price_rule->from_quantity = 1;
                $specific_price_rule->price = $_COOKIE['price'];
                $specific_price_rule->reduction_tax = 1;
                $specific_price_rule->reduction = 0;
                $specific_price_rule->reduction_type = 'amount';
                $specific_price_rule->from = date("Y-m-d H:i:s");
                $specific_price_rule->to = "0000-00-00 00:00:00";

                //SpecificPrice()
                $specific_price = new SpecificPrice();
                $specific_price->id_product = (int)$this->id_product; // choosen product id
                $specific_price->id_product_attribute = 0;//$product->getDefaultAttribute($product->id);
                $specific_price->id_cart = (int)$this->context->cart->id;
                $specific_price->id_shop = $this->context->shop->id;;
                $specific_price->id_currency = $this->context->currency->id;
                $specific_price->id_country = $this->context->country->id;;
                $specific_price->id_group = $this->context->customer->id_default_group;
                $specific_price->id_customer = $this->context->customer->id ? $this->context->customer->id : NULL;
                $specific_price->from_quantity = 1;
                $specific_price->price = $_COOKIE['price'];
                $specific_price->reduction_type = 'amount';
                $specific_price->reduction_tax = 1;
                $specific_price->reduction = 0;
                $specific_price->from = date("Y-m-d H:i:s");
                $futureDate = strtotime(date("Y-m-d H:i:s"))+(60*60);
                $specific_price->to = date("Y-m-d H:i:s", $futureDate);
                $specific_price->id_specific_price_rule = $id_specific_price_rule;
                    
                    
            }
        }
        parent::initContent();
    }
}

===============

The appropriate entries are made in the tables:

  • ps_specific_price

  • ps_specific_price_rule

 

 

After pressing the 'Add to Cart' button, the original price still appears and only after a few or several dozen seconds, when I refresh the Cart, the correct price appears.

 

What could be the reason?

Maybe there is a cache somewhere, but I can not find it?

Maybe you have an idea how to solve it?

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...