Jump to content

how the function refreshWishlist works (ps 1.3.7)


allienato
 Share

Recommended Posts

hi, I'm wondering if anyone knows how the function refreshWishlist (in modules/blockwishlist/Wishlist.php) works and what exactly do. there's no descriptions in reference

this is the standard code (prestashop 1.3.7)

static public function refreshWishList($id_wishlist)
   {
       $old_carts = Db::getInstance()->ExecuteS('
       SELECT wp.id_product, wp.id_product_attribute, wpc.id_cart, UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(wpc.date_add) AS timecart
       FROM `'._DB_PREFIX_.'wishlist_product_cart` wpc
       JOIN `'._DB_PREFIX_.'wishlist_product` wp ON (wp.id_wishlist_product = wpc.id_wishlist_product)
       JOIN `'._DB_PREFIX_.'cart` c ON  (c.id_cart = wpc.id_cart)
       JOIN `'._DB_PREFIX_.'cart_product` cp ON (wpc.id_cart = cp.id_cart)
       LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.id_cart = c.id_cart)
       WHERE (wp.id_wishlist='.intval($id_wishlist).' AND o.id_cart IS NULL)
       HAVING timecart  >= 3600*6');

       if(isset($old_carts) AND $old_carts != false)
           foreach ($old_carts AS $old_cart)
               Db::getInstance()->Execute('
                   DELETE FROM `'._DB_PREFIX_.'cart_product`
                   WHERE id_cart='.intval($old_cart['id_cart']).' AND id_product='.intval($old_cart['id_product']).' AND id_product_attribute='.intval($old_cart['id_product_attribute'])
               );

       $freshwish = Db::getInstance()->ExecuteS('
           SELECT  wpc.id_cart, wpc.id_wishlist_product
           FROM `'._DB_PREFIX_.'wishlist_product_cart` wpc
           JOIN `'._DB_PREFIX_.'wishlist_product` wp ON (wpc.id_wishlist_product = wp.id_wishlist_product)
           JOIN `'._DB_PREFIX_.'cart` c ON (c.id_cart = wpc.id_cart)
           LEFT JOIN `'._DB_PREFIX_.'cart_product` cp ON (cp.id_cart = wpc.id_cart AND cp.id_product = wp.id_product AND cp.id_product_attribute = wp.id_product_attribute)
           WHERE (wp.id_wishlist = '.intval($id_wishlist).' AND ((cp.id_product IS NULL AND cp.id_product_attribute IS NULL)))
           ');
       $res = Db::getInstance()->ExecuteS('
           SELECT wp.id_wishlist_product, cp.quantity AS cart_quantity, wpc.quantity AS wish_quantity, wpc.id_cart
           FROM `'._DB_PREFIX_.'wishlist_product_cart` wpc
           JOIN `'._DB_PREFIX_.'wishlist_product` wp ON (wp.id_wishlist_product = wpc.id_wishlist_product)
           JOIN `'._DB_PREFIX_.'cart` c ON (c.id_cart = wpc.id_cart)
           JOIN `'._DB_PREFIX_.'cart_product` cp ON (cp.id_cart = wpc.id_cart AND cp.id_product = wp.id_product AND cp.id_product_attribute = wp.id_product_attribute)
           WHERE wp.id_wishlist='.intval($id_wishlist)
       );

       if(isset($res) AND $res != false)
           foreach ($res AS $refresh)
               if($refresh['wish_quantity'] > $refresh['cart_quantity'])
               {
                   Db::getInstance()->Execute('
                       UPDATE `'._DB_PREFIX_.'wishlist_product`
                       SET `quantity`= `quantity` + '.(intval($refresh['wish_quantity']) - intval($refresh['cart_quantity'])).'
                       WHERE id_wishlist_product='.intval($refresh['id_wishlist_product'])
                   );
                   Db::getInstance()->Execute('
                       UPDATE `'._DB_PREFIX_.'wishlist_product_cart`
                       SET `quantity`='.intval($refresh['cart_quantity']).'
                       WHERE id_wishlist_product='.intval($refresh['id_wishlist_product']).' AND id_cart='.intval($refresh['id_cart'])
                   );
               }
       if(isset($freshwish) AND $freshwish != false)
           foreach ($freshwish AS $prodcustomer)
           {
               Db::getInstance()->Execute('
                   UPDATE `'._DB_PREFIX_.'wishlist_product` SET `quantity`=`quantity` +
                   (
                       SELECT `quantity` FROM `'._DB_PREFIX_.'wishlist_product_cart`
                       WHERE `id_wishlist_product`='.intval($prodcustomer['id_wishlist_product']).' AND `id_cart`='.intval($prodcustomer['id_cart']).'
                   )
                   WHERE `id_wishlist_product`='.intval($prodcustomer['id_wishlist_product']).' AND `id_wishlist`='.intval($id_wishlist)
                   );
               Db::getInstance()->Execute('
                   DELETE FROM `'._DB_PREFIX_.'wishlist_product_cart`
                   WHERE `id_wishlist_product`='.intval($prodcustomer['id_wishlist_product']).' AND `id_cart`='.intval($prodcustomer['id_cart'])
                   );
           }
   }



it is called in modules/blockwishlist/view.php, before get the products list

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More