Tôi đang thêm một sản phẩm danh nghĩa theo chương trình vào giỏ hàng. Nhưng nó ném một ngoại lệ như 'The stock item for Product is not valid.'. Làm thế nào tôi có thể giải quyết điều này?
LƯU Ý: $productđang được chuyển đến chức năng này một cách chính xác.
Mã của tôi là như sau.
    /**
     * Add air product to the cart.
     */
    public function addSubscriptionToCart($product)
    {
        try {
            // Create cart instance.
            $cart = Mage::getModel('checkout/cart');
            // Initialize the cart.
            $cart->init();
            $cart->addProduct($product, array('product_id' => $product->getId(), 'qty' => 1)); // This line causes the error.
            $cart->save();
            return true;
        } catch(Exception $e) {
            Mage::log($e->getMessage());
            return false;
        }
    }
          
Fatal error: Uncaught TypeError: Argument 1 passed to Mage_Sales_Model_Quote::addProduct() must be an instance of Mage_Catalog_Model_Product, string given, called in