duandie0884 2012-07-30 12:16
浏览 49
已采纳

Magento - 预览产品但需要登录才能购买

I'm actually discussing with a customer about the need to integrate social network sharing within their magentocommerce.

The customer wants a user to be able to share on facebook a product, and allow a "preview" of the product to non logged users (that may want to follow the link through facebook itself), but then require the login to purchase the item.

I told them to disable the login for the whole site, and require it only for the checkout (that's the best way also to get indexed by google), but they asked me to create some sort of preview for non-logged users, and require then a login to view the "add to cart" button.

Is it easily doable? Is it worth it? I'm still thinking the best solution would be require the login only for the checkout.

Do you have any link/demo that can show me up some sort of preview but then require a login? I'm actually thinking about the way ebay shows things to non-logged users.

  • 写回答

3条回答 默认 最新

  • doupeng5320 2012-07-30 16:14
    关注

    Please try to avoid littering your templates with Mage::getSingleton('customer/session')->isLoggedIn() as has been previously suggested to you.

    If you only have to deal with the add to cart functionality on product view, then you all you require is a little layout xml...

    <customer_logged_out>
        <remove name="product.info.addtocart" />
    </customer_logged_out>
    

    Nice, clean and easy.

    If however, you have to deal with site wide i.e. product view, product list etc then I would suggest you create an observer that subscribes to catalog_product_is_salable_after. This event gets fired, not suprisingly, after every call to Mage_Catalog_Model_Product isSalable - you will therefore have an opportunity to force a product to not be salable if the customer is not logged in.

    Obviously you do need create a module, but this is IMO the best option and worth the little extra effort that it takes.

    So, to create the observer, you will need to add the following to the frontend node of your config.xml:

    <events>
        <catalog_product_is_salable_after>
            <observers>
                <yourmodule>
                    <class>Yourcompany_Yourmodule_Model_Observer</class>
                    <method>catalog_product_is_salable_after</method>
                </yourmodule>
            </observers>
        </catalog_product_is_salable_after>
    </events>
    

    Your observer will require the following:

    class Yourcompany_Yourmodule_Model_Observer
    {
        public function catalog_product_is_salable_after(Varien_Event_Observer $observer)
        {
            if (! Mage::helper('customer')->isLoggedIn()) {
                 $observer->getEvent()->getData('salable')
                     ->setData('is_salable', false);
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行