在商店级别创建结帐会话
我正在尝试在商店级别(而不是站点级别)为登录客户创建不同的结账会话。
我们有一个拥有 2 家商店的网站。当用户将产品添加到购物车时,我们希望仅在该商店的购物车中显示该产品。但目前在商店之间切换会显示之前添加到购物车的其他商店的产品。
经过一些研究,我发现每当用户登录商店时,都会在 sales_flat_quote
表中为登录的客户创建一条记录,这对于该站点中的所有商店来说都是常见的。因此,当用户切换商店时,我需要在 sales_flat_quote
表中创建一条新记录。
我发现 Mage_Sales_Model_Mysql4_Quote
类中的 loadByCustomerId()
函数是在 sales_flat_quote 表
中创建新记录的函数。但我看到的只是一个选择查询:
$read = $this->_getReadAdapter();
$select = $this->_getLoadSelect('customer_id', $customerId, $quote)
->where('is_active=1')
->order('updated_at desc')
->limit(1);
$data = $read->fetchRow($select);
我不明白选择查询如何在 sales_flat_quote
表中创建记录。
有人可以指导当登录的客户切换到同一站点下的其他商店时如何在此表中创建新记录吗?
I'm trying to create different checkout sessions for the logged in customer at a store level, rather than at the site level.
We have a site with 2 stores. When a user adds a product to the cart, we want to show that product in the cart only for that store. But currently switching between stores will show up products of other stores previously added to the cart.
After some research I found that whenever a user logs in to a store, a record is created in the sales_flat_quote
table for the logged in customer, which is common for all the stores in that site. So I need to create a new record in the sales_flat_quote
table when the user switches stores.
I found that the loadByCustomerId()
function in class Mage_Sales_Model_Mysql4_Quote
is what creates the new record in the sales_flat_quote table
. But all I see is a select query:
$read = $this->_getReadAdapter();
$select = $this->_getLoadSelect('customer_id', $customerId, $quote)
->where('is_active=1')
->order('updated_at desc')
->limit(1);
$data = $read->fetchRow($select);
I don't understand how the select query is creating the record in the sales_flat_quote
table.
Could someone guide as to how to create a new record in this table for the logged in customer when he/she switches to an other store under the same site?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正确。
看起来您想要将
store
定义的购物车分开,它们都连接到 Magento 中相同的website
定义。在 Magento 中,同一
网站
中定义的所有商店
始终共享相同的购物车。这是设计的。
要实现购物车分离,您需要将 Magento 设置更改为每个网站有两个
网站
和一个商店
。否则,我猜您会遇到将两家商店分开的无尽问题(就像您现在遇到的问题)。尽管如此,我还是会尝试回答你的具体问题:
SELECT
查询通常永远不会创建记录;它被认为是读取数据。看一下
Mage_Checkout_Model_Session::loadCustomerQuote()
:这就是导致调用您正在讨论的
Mage_Sales_Model_Mysql4_Quote::loadByCustomerId()
的原因。它只是加载客户报价(如果有),没有其他。通过调用quotes
save()
方法来创建/更新记录。例如,Magento EE 1.11.0.0 是这样保存记录的:
您没有提到您使用的 Magento 版本,因此您的里程可能会有所不同,但原理仍然保持不变。
Which is correct.
It looks like you want to separate carts for
store
definitions, which both are connected to the very samewebsite
definition in Magento.In Magento, all
store
s defined within the samewebsite
do always share the very same cart.That's by-design.
To achieve cart separation you would need to change your Magento setup to have two
website
s and onestore
per website. Otherwise you'll run into endless issues separating the two stores (like the issue you're having now), I guess.That said, I'll nevertheless try to answer your concrete question:
A
SELECT
query usually never ever will create a record; it's thought to read data.Have a look at
Mage_Checkout_Model_Session::loadCustomerQuote()
:This is what leads to the call of
Mage_Sales_Model_Mysql4_Quote::loadByCustomerId()
you're talking about. It just loads the customers quote (if any), nothing else.Creation/update of the record happens by calling the quotes
save()
method.Magento EE 1.11.0.0 for example saves the record this way:
You didn't mention the Magento version you use, so your mileage may vary, but the principle will still remain the same.