简体   繁体   English

Magento-产品从滑块添加到迷你购物车

[英]Magento - Product add to mini cart from slider

I want to add product to mini cart from slider. 我想从滑块向迷你购物车添加产品。

Slider contain number of thumbnails of products ( It is dynamically generate from admin side. When admin is adding product, the product image will automatically adding in slider too.) 滑块包含产品缩略图的数量(它是从管理员端动态生成的。当管理员添加产品时,产品图片也会自动添加到滑块中。)

Now my question is 现在我的问题是

-> If user clicks on specific thumbnail, and click to add-to-cart button, it should be add in Mini cart in header using ajax. ->如果用户单击特定的缩略图,然后单击以添加到购物车按钮,则应使用ajax将其添加到标题的迷你购物车中。

-> If I'm getting product id with Image, Is it enough ? ->如果我通过Image获得产品ID,就足够了吗? If not, what are parameters are required ? 如果不是,则需要什么参数?

I haven't more knowledge for Magento, If you knowing even One point from above, please guide me. 我对Magento并没有更多的了解,如果您即使从上面也知道一点,请指导我。 It will me more helpful to solve out issue. 解决问题对我会更有帮助。

As of this post:(EE 1.12 or CE 1.7) 截至本文发布时间:(EE 1.12或CE 1.7)

Adding a product to the (mini) cart/cart remains relatively the same process across the site, however, where are you adding this slider? 在整个站点中,将产品添加到(微型)购物车/购物车的过程仍然相对相同,但是,您在哪里添加此滑块? Home Page? 主页? Product Listing Page? 产品详情页? Product View/Detail Page? 产品视图/详细信息页面? Other? 其他?

1) Yes, if you properly link the Product via: Link, Image, or (Add to Cart) button, you can have the item added to the cart. 1)是,如果您通过以下链接正确链接了产品:“链接”,“图像”或“添加到购物车”按钮,则可以将商品添加到购物车中。 See below. 见下文。

2) We use the ID/SKU to retrieve the product information and in turn it's Image/Small/Thumbnail images as well as Label, Short/Long Description or any other Product related data to the SKU/ID, so yes the product ID is enough information to add the product to the cart. 2)我们使用ID / SKU检索产品信息,然后依次使用图像/小/缩略图图像以及SKU / ID的标签,简短/长说明或任何其他与产品相关的数据,因此,产品ID为足够的信息来将产品添加到购物车。

Are you using a specific slider? 您是否在使用特定的滑块? Making your own? 做自己的?

Slider Template via Listing Page, read, apply, and expand; 通过列表页面的滑块模板,阅读,应用和扩展; do not just copy and paste. 不要只是复制和粘贴。

//You'll want to loop through your collection for the slider, is this collection from a category? Custom module?
<?php foreach ($_productCollection as $_product): ?>

//Get/Load the Product Id when looping through a/your collection:
<?php $product = Mage::getModel('catalog/product')->load($_product->getId()); ?>

//Get the Image/Link Information you want to display for your slider:
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(100); ?>" width="100" height="100" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>            

//Basic Add to Cart: 
<?php //echo $this->helper('checkout/cart')->getAddUrl($_product) ?> 
//Ajax Button
<button onclick="productAddToCartForm.submit()" class="button btn-cart"><span><span>Get a Quote</span></span></button>

//Basic Javascript for Button
<script type="text/javascript">
//<![CDATA[
        var productAddToCartForm = new VarienForm('product_addtocart_form');
        productAddToCartForm.submit = function(){
                if (this.validator.validate()) {
                        this.form.submit();
                }
        }.bind(productAddToCartForm);
//]]>
</script>

For additional Details, the following provides a complete implementation as well. 对于其他详细信息,以下内容也提供了完整的实现。 The following provides a good example of the logic though: http://tutorialmagento.com/add-multiple-product-to-cart-using-magento-ajax-add-cart 下面提供了一个很好的逻辑示例: http : //tutorialmagento.com/add-multiple-product-to-cart-using-magento-ajax-add-cart

-- Update: Magento's EE Iphone Theme also add's in a visual for adding the product to the cart. -更新:Magento的EE Iphone主题还会在视觉效果中添加,以将产品添加到购物车。

Please see the following file (EE 1.12), I'll have to check to see if this is available in CE, keep in mind this is a Detail page and targeting product ID's on the home page will be different, however, once the Product ID is found, the rest is applicable. 请参阅以下文件(EE 1.12),我必须检查一下CE中是否提供此文件,请记住,这是“详细信息”页面,并且主页上的定位产品ID会有所不同,但是,找到ID,其余的都适用。

app/design/frontend/enterprise/iphone/template/catalog/product/view.phtml app / design / frontend / enterprise / iphone / template / catalog / product / view.phtml

<?php // SAMPLE?>
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
    var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->setEscapeMessageFlag(true)->toHtml() ?></div>
<div class="product-view">
    <form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
        <div class="no-display">
            <input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
            <input type="hidden" name="related_product" id="related-products-field" value="" />
        </div>
        <div class="product-essential">

                <div class="product-img-box">
                    <?php echo $this->getChildHtml('media') ?>
                </div>

                <div class="product-shop">
                    <div class="product-main-info">
                        <div class="product-name">
                            <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
                        </div>
                        <?php echo $this->getChildHtml('alert_urls') ?>
                        <?php echo $this->getChildHtml('product_type_data') ?>
                    </div>
                    <?php echo $this->getChildHtml('tierprices') ?>
                    <?php echo $this->getChildHtml('extrahint') ?>

                    <?php if (!$this->hasOptions()):?>
                        <div class="add-to-box">
                            <?php if($_product->isSaleable()): ?>
                                <?php echo $this->getChildHtml('addtocart') ?>
                            <?php endif; ?>
                        </div>
                    <?php else:?>
                        <?php if ($_product->isSaleable() && $this->hasOptions() && $this->getChildChildHtml('container1') ):?>
                            <div class="options-container-small">
                                <?php echo $this->getChildChildHtml('container1', '', true, true) ?>
                            </div>
                        <?php endif;?>
                    <?php endif; ?>

                    <?php echo $this->getChildHtml('other');?>
                </div>

        </div>

// ------- // -------

<script type="text/javascript">
//<![CDATA[
    var productAddToCartForm = new VarienForm('product_addtocart_form');
    productAddToCartForm.submit = function(button, url) {
        if (this.validator.validate()) {
            var form = this.form;
            var oldUrl = form.action;

            if (url) {
               form.action = url;
            }
            var e = null;
            try {
                var transformValue = {};

                if ( Modernizr.csstransforms3d ) {
                    transformValue[Modernizr.prefixed('transform')] = 'translate3d(-82px, -106px, 2px) scale(0) rotate(200deg)';
                } else if ( Modernizr.csstransforms ) {
                    transformValue[Modernizr.prefixed('transform')] = 'translate(-82px, -106px) scale(0) rotate(200deg)';
                } else {
                    this.form.submit();
                    return false;
                }

                var originalImg = $$('.product-image-wrap .product-image img')[0];
                originalImg.up('.product-image-wrap').insert(originalImg.clone().addClassName('cloned'));

                setTimeout(function () {
                    $$('.cloned')[0].setStyle(transformValue);
                }, 1);
                $$('.product-image-wrap .cloned')[0].observe(transEndEventName, function(e) {
                    this.form.submit();
                }.bind(this));

            } catch (e) {
            }
            this.form.action = oldUrl;
            if (e) {
                throw e;
            }

            if (button && button != 'undefined') {
                button.disabled = true;
            }
        }
    }.bind(productAddToCartForm);

    productAddToCartForm.submitLight = function(button, url){
        if(this.validator) {
            var nv = Validation.methods;
            delete Validation.methods['required-entry'];
            delete Validation.methods['validate-one-required'];
            delete Validation.methods['validate-one-required-by-name'];
            if (this.validator.validate()) {
                if (url) {
                    this.form.action = url;
                }
                this.form.submit();
            }
            Object.extend(Validation.methods, nv);
        }
    }.bind(productAddToCartForm);
//]]>
</script>

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

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