Magento - Wishlist addNewItem remove all my items - php

I got a problem with my whislist. Here is the thing.
I try to programmatically add into a whistlist, a new Item.
So I use the $whishlist->addNewItem() function. The product is added, but if I had other products in my whislist, they've been removed!
Here is what I use:
<?php
$customer = Mage::getModel('customer/customer')->load($my_customer_id);
$product = Mage::getModel('catalog/product')->load($my_product_id);
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true);
$request = new Varien_Object(array());
$result = $wishlist->addNewItem($product, $request);
$wishlist->save();
?>
Did I do something wrong?
Thank you guys
EDIT:
I Finally found, it seems weird, but in my case, I have to remove this line $wishlist->save();

I had to remove this line $wishlist->save();
I don't know if it's THE solution, but it works for me.
Thank's to everyone :)

Remove the ->save on the wishlist. Sometimes it works

This might help you,
Lets say you have to add a product to wishlist on click so it would be like :
<a onclick="setLocation('<?php echo $this->helper('wishlist')->getAddUrl(Mage::registry('current_product'));?>')">add to wishlist</a>

I too had the same problem. But in my case product visibility in magento backend is set to "Not Visible Individually". changed product visibility and it worked.

I had the same problem and the "save" function was not in cause.
My problem came from the products redindexation. I've found my solution here : Why is my wish list limited to one item?
Reindexing every indexes made my wishlist worked again for products recently added through the rest API.
To do it automatically, I've change this index to "Update on Save" in the admin : Product Flat Data - Reorganize EAV product structure to flat structure.
My wishlist works perfectly fine now (even with the "save" function).

Related

Changing the price text in b2bking plugin

The b2bking plugin has helped me alot with my shop. One of its features in that it can display both a wholesale and a retail price.
My problem is that we are a swedish shop and I would like it to say "ÅF-pris" and "RRP" instead of what is outputs by default.
I've tried modifying the code inside the plugin. It works but I know that it will stop working as soon as I update the plugin. This is why I want to do it with filter hooks provided by the plugin.
What I've tried (I am kinda new to PHP)
add_filter('b2bking_filter_wholesale_price_final', 'alex_translate_price_text');
function alex_translate_price_text($text_retail_price, $text_final_price){
$text_retail_price = 'test_RRP: ';
return $text_retail_price;
$text_final_price = 'test_åf-pris: ';
return $text_final_price;
}
in the plugin, hook looks like this:
$price = apply_filters('b2bking_filter_wholesale_price_final', $price, $text_retail_price, $retail_price, $text_final_price, $b2b_price_price, $product_id);
My thought process is that I want to change the variables "$text_retail_price" and "$text_final_price" to "ÅF-pris" and "RRP" as right now they contain "Retail price" and "Wholesale price".
We're the developers of the plugin, glad to hear it's been useful to you,
There's now a setting where you can change these directly via B2BKing -> Settings -> Language & Text.

Add product from wishlist to quote in magento

I have problem in wishlist
I need to move products from wishlist to enquiry quote
$url = Mage::getUrl('qquoteadv/index/addItem/');
$actionQuote = "addQuote('".$url."');"
i tried above code but its not working
any suggestion for this query?
I don't know Magento, but I think addQuote is function, so it should be
$actionQuote = addQuote($url);
qquoteadv is the name of the Magento Cart2Quote extension, so that url won't work if you don't have it installed.
Also, your url is missing the product id:
qquoteadv/index/addItem/ should be qquoteadv/index/addItem/product/123/ for example. And it only add's one product.
You could call this url multiple times using ajax, then the url should be qquoteadv/index/addItemAjax/product/123/ that way you could add the whole wishlist to the quote.

Magento Add to Wishlist code not working

I am using this snippet of code to add a wishlist to my product view
<a onclick="setLocation('<?php echo $this->getAddToWishlistUrl($_product) ?>')"
class="buttons-wish" title="<?php echo $this->__('Add to Wishlist') ?>"></a>
<a onclick="setLocation('<?php echo $this->getAddToCompareUrl($_product) ?>')"
class="buttons-compare" title="<?php echo $this->__('Add to Compare') ?>"></a>
But for some reason it is not working.
I need help to resolve the issue
Try this one.
<?php echo $this->__('Add to Wishlist') ?>
<?php echo $this->__('Add to Compare') ?>
One problem I found with the wishlist in Magento 1.8 is to do with the new form_key parameter, maybe this is what's caused the problem for you.
Magento 1.8 introduces form keys (they may have existed prior to 1.8 in some form, but now they're everywhere). They are mandatory if you want any of your forms to do anything. Want to add to cart / wishlist / comparison list? Need a form key. Want to submit a contact form? Need a form key. Want to log in? Form key. Etc.
All the necessary core templates have been updated to include this key as a hidden input element - in my experience you just need to copy and paste this line from any of a dozen different places into any custom templates you have (somewhere inside the form element) and they'll be fine too.
So all's well - a further security enhancement / spam prevention feature, and easy enough to accommodate.
The problem is that $this->helper('wishlist')->getAddUrl($_product) generates a URL that also contains this form key, e.g. /wishlist/index/add/product/101/form_key/xyz which simply doesn't work. And in this case, by "doesn't work", I mean the "add to wishlist" button doesn't add anything to your wishlist, although it does still take you to your wishlist page.
Whether by accident or by design I'm not sure, but it seems that form_key doesn't work in the URL like most Magento parameters do. It has to be a standard HTTP variable e.g. an input in a form field or added to the query string in a URL like ?form_key=xyz.
On the product view at least, and I think on the list view as well, the wishlist button actually calls productAddToCartForm.submitLight(), which means the URL doesn't need the form key at all, since productAddToCartForm already contains it.
How to fix it? As with most things there are a number of ways. You could stop using $this->helper('wishlist')->getAddUrl($_product) and replace it with something like $this->getStoreUrl('wishlist/index/add/product/'.$_product->getId()) (I haven't tested that so use with caution) or you could override Mage_Wishlist_Helper_Data::getAddUrl which is how I chose to do it. That way affects all templates etc that try to use an "add to wishlist" url, which could be a good thing or a bad thing. I think good, in this case, but it's up to you.
I copied Mage/Wishlist/Helper/Data.php from app/code/core to app/code/local and changed:
public function getAddUrl($item)
{
return $this->getAddUrlWithParams($item);
}
to:
public function getAddUrl($item)
{
$productId = null;
if ($item instanceof Mage_Catalog_Model_Product) {
$productId = $item->getEntityId();
}
if ($item instanceof Mage_Wishlist_Model_Item) {
$productId = $item->getProductId();
}
if ($productId) {
$params = array('product' => $productId);
return $this->_getUrlStore($item)->getUrl('wishlist/index/add', $params);
}
return false;
}
...which is simply a copy of the getAddUrlWithParams function with the "params" hard-coded to just the product id.
Check in the backend System->Configuration->Advanced->Advanced->Disable Modules Output
Mage_Wishlist is enabled or not.
I have faced a similar issue. Click on "Add to wishlist" and the page gets redirected to my favorites page with the below mentioned error message.
We can't add the item to Wish List right now: Cannot add product without stock to wishlist..
Solution: There is no issue with wishlist functionality. By default, Magento 2 ships with the wishlist functionality enabled. In our case, we were using multiple custom sources. You can check this out by visiting
Admin-> stores-> sources (if you see apart from the default source)
If you wish to disable the default source.
Admin -> Stores -> Configuration -> Catalog -> Inventory -> Product stock options -> Set the manage stock = NO
refer https://docs.magento.com/user-guide/catalog/inventory.html

Magento - Embed pictures on product page

I've embedded some extra pictures and videos on my product pages, but when I create a new without setting a picture, Magento creates an error because it cannot find the picture, that is not set. I've created an attribute in Magento named embed3, an image attribute.
Then I made this snippet, which works great - except if no pictures are chosen Magento fails:
<?php
$video3 = $_product->getEmbed3();
if (isset($video3)){
echo '<img src="';
echo $this->helper('catalog/image')->init($_product, 'embed3');
echo '"/>';
}
else
{
}
?>
It's crude and ugly - I know, any suggestions/help will be much appreciated
Are you using this snippet in product view?
Use the following instead of $video3 = $_product->getEmbed3(). getAttribute() always exists for a product resource, while magic methods don't.
$video3 = $_product->getResource()->getAttribute('embed3');
Sadly that didn't work #F. Haymar d'Ettory :( it only created errors on all my products. But I found out that, while it works well on products I've created in the past, and products with pictures isset was also working, when creating new products and not setting a picture, Magento set it as "no_selection" - and the isset then think's that theres actually an image set, but here is not. So by creating this:
if (isset($video3)&&($video3 != 'no_selection')){
it works again, still not pretty but it works.

Magento bundle dropdown need to display out of stock

In a bundle product page, I need to display if a product in the bundle is out of stock. Currently, the product is simply not appearing in the dropdown. I've looked at the "select.phtml" file and found at the beginning that this line of code get the option value for the dropdown :
<?php $_selections = $_option->getSelections(); ?>
Unfortunately, this doesn't fetch "out of stock" items. So, is there a way to include these items?
Thank you.
Hoping this can help someone. After searching for hours, finally found the line that was causing the problem inside app/code/core/Mage/Bundle/Block/View/Type/Bundle.php
You need to change this line
$this->_options = $optionCollection->appendSelections($selectionCollection, false,
Mage::helper('catalog/product')->getSkipSaleableCheck()
);
to this
$this->_options = $optionCollection->appendSelections($selectionCollection, false,
true
//Mage::helper('catalog/product')->getSkipSaleableCheck()
);
Building on SimCity's answer, rather than extending/overwriting the block, you can do the following. I have added this code to the top of bundle/catalog/product/view/type/bundle/options.phtml
// Get the current value of SkipSaleableCheck
<?php $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck() ?>
// Overwrite this value with a 'true' value
<?php Mage::helper('catalog/product')->setSkipSaleableCheck(true) ?>
You can then reset this value at the bottom of the same file using the following code:
<?php Mage::helper('catalog/product')->setSkipSaleableCheck($skipSaleableCheck) ?>
This method provides the same result without having to overwrite core Magento blocks.
In Magento 1.8.1 you find the file in app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php
Be aware of making changes in the core will get you site no good for updates. Make a copy of your file to your local directory.

Categories