Sylius ShopApiPlugin无法将产品添加到购物车

时间:2018-12-27 16:18:52

标签: symfony sylius

我正在尝试使用为Sylius制作的ShopApiPlugin将产品添加到购物车中。 当我尝试通过/carts/mytokenoid/items通过json正文添加产品时 { "productCode": "iphone9", "quantity": 5 }

我得到这个答复

{
"tokenValue": "mytokenoid",
"channel": "US_WEB",
"currency": "EUR",
"locale": "en_US",
"checkoutState": "cart",
"items": [
    {
        "quantity": 5,
        "total": 4800,
        "product": {
            "code": "iphone9",
            "name": "iPhone 9",
            "slug": "iphone-9",
            "averageRating": 0,
            "taxons": {
                "others": []
            },
            "variants": [
                {
                    "code": "iphone9",
                    "axis": [],
                    "nameAxis": [],
                    "price": {
                        "current": 2000,
                        "currency": "EUR"
                    },
                    "images": []
                }
            ],
            "attributes": [],
            "associations": [],
            "images": []
        }
    }
],
"totals": {
    "total": 6896,
    "items": 4800,
    "taxes": 0,
    "shipping": 2096,
    "promotion": -5200
}, (...)

但是,当我执行/shop-api/carts/mytokenoid检查购物车内容时,它为空,则未添加任何内容。我也检查了数据库,购物车上有正确的令牌,但没有物品。 有谁知道我该怎么解决?我已经尝试过使用授权令牌,而没有使用。有同样的事情

1 个答案:

答案 0 :(得分:0)

找到了解决方案。 您只需要取消注释[HttpGet] [ActionName("GetData")] public object Get() { List<SelectData> TestList = new List<SelectData>(); string connStr = ConfigurationManager.AppSettings.Get("ConnStr"); using (var conn = new OracleConnection(connStr)) { conn.Open(); OracleCommand cmd = new OracleCommand(); cmd.CommandText = "select * from DB_DATA"; cmd.Connection = conn; OracleDataReader dr = cmd.ExecuteReader(); SelectData ListObject = new SelectData(); while (dr.Read()) { //Error if any of these are null ListObject.DATA_ID = dr.GetInt32(0); ListObject.Name = dr.GetString(1); ListObject.LastName = dr.GetString(2); ListObject.COMMENTS = dr.GetString(3); ListObject.Address = dr.GetString(4); TestList.Add(ListObject); } conn.Close(); } return TestList; }

中的“-tactician.middleware.doctrine”行即可。