I have the following class i am using to test adding to cart in a custom way;
use Magento\Framework\App\Action;
use Magento\Checkout\Model\Cart;
class Add extends Action\Action
{
protected $cart;
public function __construct(
Action\Context $context,
Cart $cart
){
$this->cart = $cart;
parent::__construct($context);
}
public function execute()
{
$this->cart->addProductsByIds([1])
->save();
}
}
This works great. When you view the cart it shows my item, all looks cool in the database etc. However, the minicart still shows as if there are no items in the basket.
If i then add another product to the cart using the "add to cart" button on the product or listing pages it adds to the cart and updates the minicart to show both items.
Where does it trigger the minicart to update itself or how does the minicart know it needs to refresh?