Attempting to return a selected list of Products using PHP/Javascript API.

Shopify Partner
40 4 2

Obviously I am new and attempting my first Shopify App. I choose to use PHP / Javascript. 


In the below code example on my test store I can successfully Select Products through the Button. Checked the console and the correct selected array exists. Yay! However, I am trying to use Cookies to save the Selected list. And there is no output from: print_r(selected); 

Can some kind soul please tell me what I am doing incorrectly or if there is a better way to return the selected array?

Thank you.






<?php include_once("header.php"); ?>
// Creating a cookie after the document is ready
$(document).ready(function () {
    createCookie("efc", "EdwardC", "10");
// Function to create the cookie
function createCookie(name, value, days) {
    var expires;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    else {
        expires = "";
    document.cookie = escape(name) + "=" + 
        escape(value) + expires + "; path=/";

<button id="open-picker">Select Products</button>

.addEventListener('click', async () => {
const selected = await shopify.resourcePicker({type: 'product', multiple: true});


$selected = $_COOKIE['selected'];
echo print_r($selected);

echo $_COOKIE["efc"];

<?php include_once("footer.php"); ?>


Reply 1 (1)

Shopify Staff
2731 302 777

HI ScinteraShopy,


It looks like you're not setting the cookie for the selected products in your JavaScript code. The selected products are being logged to the console, but they're not being saved to a cookie.


You can set the cookie in your JavaScript code right after logging the selected products to the console. You may need to stringify the selected products array because cookies can only store strings. Then, in your PHP code, you can retrieve and decode the cookie.


Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit or the Shopify Web Design and Development Blog