在grails的购物车方法

时间:2013-04-10 14:19:14

标签: grails shopping-cart

我正在尝试购物车应用程序。我使用过Spring安全性。

我尝试在PurchaseOrder域中实现一个方法,如下所示:

public void addToItems(Products products){

    def purchaseItem = items?.find{it.products == products} 

    if (purchaseItem == null){
        if (items == null){
            items = []
        }
        items.add(new PurchaseItem(products:products,purchaseOrder:this,quantity:1,price:products.price))
    }
    else{  
        purchaseItem.quantity += 1
        purchaseItem.price = products.price
    }

}

,这是在UserController.groovy

def addToCart = {

    def products = Products.get(params.productsId)

    if (products == null){
        flash.error = "Could not add product to cart! Could find product with id [${params.productsId}]."
        redirect(controller:'userInfo',action:'productSearch')
    }

    def purchaseOrderInstance = PurchaseOrder.findByUser(currentUser())
    if (purchaseOrderInstance == null){
        purchaseOrderInstance = new PurchaseOrder(user:currentUser())
    }

    purchaseOrderInstance.addToItems(products)

    purchaseOrderInstance.save(flush:true)


    redirect(action:'cart')
}

但我收到了这个错误:

Message: No signature of method: com.shop.PurchaseOrder.addToItems() is applicable for argument types: (null) values: [null]
Possible solutions: addToItems(java.lang.Object), addToItems(com.shop.Products), getItems()
    Line | Method
->>  118 | doCall    in com.shop.UserInfoController$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    195 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run       in java.lang.Thread

我不确定哪里出错了,错误是什么意思?

0 个答案:

没有答案