简体   繁体   English

使每个商品/商品的愿望清单动态化

[英]Make Wish List Dynamic for each item/ article

HI i got a little Problem i have whish list script which adds artivcles from shop into a session and saves them but when i click on the which list he only adds the first item how to male it dynamic that every wish list click is for the individual item in the shop 嗨,我有一个小问题我有一个愿望清单脚本,该脚本将商店中的关节添加到会话中并保存,但是当我单击哪个清单时,他仅添加了第一项如何动态显示每个愿望清单针对个人的动态方式商店里的物品

my article structure, onclick of wlbutton1 or wlbutton2 he should add the article with id1 or 2 to the wishlist: 我的文章结构是wlbutton1或wlbutton2的onclick,他应将id1或2的文章添加到愿望清单中:

    echo '<div class="span3 filter--'.$obj->product_prop1.'" data-price="'.substr($obj->price, 0, -3) . '" data-popularity="3" data-size="s|m|xl" data-color="pink|orange" data-brand="'.$obj->product_brand.'">'; 
        echo '<div class="product">'; 
        echo '<div class="product-img featured">'; 
        echo '<form method="post" action="../cart_update.php">';
        echo '<div class="picture"><img src="images/'.$obj->product_img_name.'">';
        echo '<div class="img-overlay"><button class="add_to_cart btn more btn-primary">Kaufen</button><a href="#" class="btn buy btn-danger" id="producturl'.$obj->id.'">...mehr</a></div>';
        echo '</div>';
        echo '</div>';
        echo '<div id="result"></div>';
        echo '<div class="main-titles"><h4 class="title">'.$currency.$obj->price.'</h4>';
        echo '<h5 class="no-margin isotope--title" id="product'.$obj->id.'">'.$obj->product_name.'</h5>';
        echo '<p class="no-margin pacifico" style="position: absolute;right: 10px;top: 5px; text-transform: capitalize;">'.$obj->product_brand.'</p>';
        echo '<p class="no-margin" style="position: absolute;right: 10px;top: 25px;"><a class="wl-button'.$obj->id.'"><i class="icon-gift"></i></a></p>';
        echo '</div>';
        echo '<p class="desc">'.substr($obj->product_desc, 0, 160) . '...</p>';
        echo '<input type="hidden" name="product_qty" value="1" />';
        echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
        echo '<input type="hidden" name="type" value="add" />';
        echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
        echo '</form>';
        echo '</div>';
        echo '</div>';

My Jquery Code how to make it dynamic and individual for eacht artivle?: 我的jQuery代码如何使每个商品的动态和个性化?

$(".wl-button").click(function() {
    var wlproduct = $('#product').text();
    var wlproducturl = $('#producturl').attr('href');
    $.ajax({
        type : "POST",
        url : "../assets/wlscript.php",
        data : { wlproduct : wlproduct, wlproducturl : wlproducturl },
        success : function(data) { 
        $('div#result').text('You added '+wlproducturl+' '+wlproduct+'\'s to your wishlist.');
        }
    }); 
}); 

Here an example of how you can do to find the data you need to add your article. 这里有一个示例,说明如何查找添加文章所需的数据。 First the HTML example : 首先是HTML示例:

<div class="products">
    <form>
        <p>
            <!-- Fist article -->
            <span>Article 1</span>
            <!-- A name construct so that I can easilly find in which iteration of the loop I am -->
            <input type="hidden" name="article[0].id" value="1" />
            <input type="hidden" name="article[0].name" value="article1" />
            <button class="addButton">Add article</button>
        </p>
        <p>
            <!-- Second article -->
            <span>Article 2</span>
            <input type="hidden" name="article[1].id" value="2" />
            <input type="hidden" name="article[1].name" value="article2" />
            <button class="addButton">Add article</button>
        </p>
        <!-- … others articles -->
    </form>
</div>

And the Javascript part : 和Javascript部分:

$(document).ready(function(){
    $(".addButton").on("click", function(event){
        event.preventDefault();
        var button = $(this);
        var parent = button.parent(); // We need to find the container in which to seach our fields.
        var idArticle = parent.find("input[name$='.id']").val(); // Find the ID
        var nameArticle = parent.find("input[name$='.name']").val(); // Find ather data
        alert("Add article with id = " + idArticle + " and name = " + nameArticle);
        // Next step is the ajax method to call the server with the correct data. 
    });
});

By working like that, you can then send to your server the data you need to add an article to your wishlist. 通过这种方式,您可以将需要添加文章到愿望清单的数据发送到服务器。

Here the link to the JS Fiddle example . 这里是JS Fiddle示例的链接。

In this example, you can see how to work around the HTML content from the button to find the inputs. 在此示例中,您可以从按钮中查看如何处理HTML内容以查找输入。

You can find more about "tree traversal" with the jQuery API . 您可以使用jQuery API找到有关“树遍历”的更多信息。

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

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