I did something like that, you have to save your wishlist before sharing the link.
So I overwrite the IndexController in the Wishlist to add a function that saves the wishlist.
Copy the
code/core/Mage/Wishlist/controllers/IndexController.php
to
code/local/Mage/Wishlist/controller/IndexController.php
and at the end paste this function (is the update function with some modifications)
public function sharedirectAction()
{
if (!$this->_validateFormKey()) {
return $this->_redirect('*/*/');
}
$wishlist = $this->_getWishlist();
if (!$wishlist) {
return $this->norouteAction();
}
$post = $this->getRequest()->getPost();
if($post && isset($post['description']) && is_array($post['description'])) {
$updatedItems = 0;
foreach ($post['description'] as $itemId => $description) {
$item = Mage::getModel('wishlist/item')->load($itemId);
if ($item->getWishlistId() != $wishlist->getId()) {
continue;
}
// Extract new values
$description = (string) $description;
if (!strlen($description)) {
$description = $item->getDescription();
}
$qty = null;
if (isset($post['qty'][$itemId])) {
$qty = $this->_processLocalizedQty($post['qty'][$itemId]);
}
if (is_null($qty)) {
$qty = $item->getQty();
if (!$qty) {
$qty = 1;
}
} elseif (0 == $qty) {
try {
$item->delete();
} catch (Exception $e) {
Mage::logException($e);
Mage::getSingleton('customer/session')->addError(
$this->__('Can\'t delete item from wishlist')
);
}
}
// Check that we need to save
if (($item->getDescription() == $description) && ($item->getQty() == $qty)) {
continue;
}
try {
$item->setDescription($description)
->setQty($qty)
->save();
$updatedItems++;
} catch (Exception $e) {
Mage::getSingleton('customer/session')->addError(
$this->__('Can\'t save description %s', Mage::helper('core')->htmlEscape($description))
);
}
}
// save wishlist model for setting date of last update
if ($updatedItems) {
try {
$wishlist->save();
Mage::helper('wishlist')->calculate();
}
catch (Exception $e) {
Mage::getSingleton('customer/session')->addError($this->__('Can\'t update wishlist'));
}
}
}
try {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$sharingCode = $wishlist->getSharingCode();
$wishlist->setShared(1);
$wishlist->save();
$this->_redirect('*//*', array('wishlist_id' => $wishlist->getId()));
}
catch (Exception $e) {
Mage::getSingleton('wishlist/session')->addError($e->getMessage());
}
}
and now in your view.phtml add this jquery code, this add the action that we just create to your form and then submit it.
jQuery(document).ready(function(){
var shareURL = '<?php echo Mage::getUrl('*/shared/index', array('code' => $this->getWishlistInstance()->getSharingCode())) ?>';
var fbUrl = "javascript:popWin('https://www.facebook.com/sharer/sharer.php?u="+shareURL+"', 'facebook', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes');";
jQuery('button.btn-share-facebook').attr("onclick", fbUrl);
jQuery('button.btn-share-facebook').click(function(e){
e.preventDefault();
jQuery('#wishlist-view-form').attr("action","<?php echo $this->getUrl('*/*/sharedirect') ?>");
jQuery('#wishlist-view-form').submit();
});
});
I don't know if is the best way, but this works for me.