简体   繁体   English

Magento API和清漆的问题

[英]Problems with Magento API and Varnish

I have a problem with cart update by API. 我通过API更新购物车时遇到问题。

I use Varnish with Phoenix. 我将Phoenix与Varnish搭配使用。

Update cart from website frontend is working fine, but if I try to update cart from API with this code, I get an old cached version of data. 从网站前端更新购物车工作正常,但是如果我尝试使用此代码从API更新购物车,则会得到旧的缓存版本的数据。

Example: If in XYZ customer's cart I have 3 products and he's adding another from web in Android app mobile which uses the API, then the cart is not updated. 示例:如果在XYZ客户的购物车中我有3种产品,并且他要在使用API​​的Android应用移动版中从Web添加另一种产品,则该购物车不会更新。

The code that I use for fetching cart details is as below: 我用于获取购物车详细信息的代码如下:

$quote     = Mage::getModel('sales/quote')->loadByCustomer($customerId);
$cartItems = $quote->getAllVisibleItems();

I think that this problem comes from the use of cookie, but I don't have an idea about how to do it. 我认为这个问题来自cookie的使用,但是我不知道该怎么做。 Obviously, if I disable varnish or if I refresh the cache everything works fine. 显然,如果禁用清漆或刷新缓存,则一切正常。

I am working on Magento 1.9.0.1, Varnish 3.0.7 and Phoenix 4.2.3 我正在开发Magento 1.9.0.1,Varnish 3.0.7和Phoenix 4.2.3

Thanks! 谢谢!

In varnish you will have to clear the cache programmatically for your changes to appear on frontend. 在清漆中,您将必须以编程方式清除缓存,以使更改显示在前端。 You can get the code to clear the cache from the controller action which is called when u clear the cache from backend. 您可以从控制器操作中获取清除缓存的代码,这是您从后端清除缓存时调用的。

Simply call this action after your API functionality is done and it will work as expected. 在您的API功能完成后,只需调用此操作即可,它将按预期运行。 You can also, Check if varnish clears cache based on any event that is fired. 您还可以根据触发的任何事件检查清漆是否清除缓存。 You can trigger this event after your functionality is done. 功能完成后,您可以触发此事件。

Also, I think u will have to do it only for the first item that user adds in cart. 另外,我认为您只需要对用户添加到购物车中的第一个商品执行此操作。 varnish cache system stops caching based on 5 dis-qualifiers - if user is logged in, if item is in wishlist, if item is added to cart, and 2 more. 清漆缓存系统基于5个取消限定符停止缓存-如果用户已登录,如果项目在心愿单中,如果该项目已添加到购物车,以及另外2个。 You can find these dis-qualifiers in its model or helper file. 您可以在其模型或帮助文件中找到这些取消限定符。 So when first item gets added to cart it should stop caching automatically for rest of the items. 因此,当第一个商品添加到购物车时,它应自动停止对其余商品的缓存。

Hope this helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM