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
Related
I am trying to change the values of the strings in the Woo Minicart plugin https://wordpress.org/support/plugin/woo-minicart/ for different languages using pll_current_language() of Polylang, but I have some trouble with Polylang and the Woo Minicart plugin. I will attach a video, because the strings change for a second, then get back to the other language. Also, the different links for the different cart pages of the languages, also do not change. Here is how it looks on the frontend: https://www.youtube.com/watch?v=tYFX34ARhF0&feature=youtu.be
I just want the strings and the links to be changed according the two different languages, please help.
Here is the code that I put in wmc-default-fragment.php and wmc-default-template.php:
<div class="wmc-bottom-buttons">
<?php if(pll_current_language() == 'en'){
echo '<a href="https://testb.com/en/cart/">'; }?>
<?php if(pll_current_language() == 'bg'){
echo '<a href="https://testb.com/количка/">'; }?>
<?php if(pll_current_language() == 'bg'){ _e( 'Количка', 'woo-minicart' );} else if(pll_current_language() == 'en'){_e( 'Cart', 'woo-minicart' ); }?></a>
<?php _e( 'Поръчка', 'woo-minicart' ) ?>
</div>
Please help me
after taking a brief look at the Polylang documentation, I found out about 'pll_language_defined', which executes after all the other functions. Look at it here: https://polylang.pro/doc/developpers-how-to/
When Polylang does load the language?
There are two cases: The language is set from the content: Polylang needs to defer the language loading and does it in a function hooked to the action 'wp' action with priority 5.
The language code is added to all urls (default): there is no need to defer the language loading and it is done as if Polylang were not active.
Due to the first case, plugin authors should not attempt to translate strings before the 'wp' action has been fired. Polylang provides a new action 'pll_language_defined' which is fired as soon as the language is defined. It works whatever the option chosen by the user to set the language.
I used pll_language_defined, I added an action inside it.
<?php
function action_pll_language_defined() {
if(pll_current_language() == 'bg'){ _e( 'Поръчка', 'woo-minicart' );} else
if(pll_current_language() == 'en') { _e( 'Checkout', 'woo-minicart' ); }
}
add_action('pll_language_defined', 'action_pll_language_defined', 10, 2);
do_action('pll_language_defined');
?>
Then it was all working, they were changing correctly. After that, I had some problems though, products were being added randomly in the cart and etc. It was problem with the plugin WP Fastest Cache. If you run into this problem, make sure you have no cache enabled for the cart page, I disabled the plugin and it was all good, everything is being translated the right way and it works now.
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).
I am new to cs-cart. Not really familiar with it. My latest project involves working with Cs-Cart. I have been able to work out how to output products and to work with categories.
Been trying this for a few weeks now. Been on few websites and stackoverflow questions. Nothing quite like what I want. The only S.O. question that came close has no answer.
I will like to have a little pop up when an item a specific item is added to the cart. In the popup div or box, I will like to suggest other items with. If possible with an add to cart button next to each suggestion.
I have searched everywhere but not much. I don't mind creating my own plugin for this but I don't know how to listen to those add to cart events and creating popups in cs-cart.
Any help is appreciated ..
If you add a product to cart in CS-Cart, you have a pop-up box. By default, the add to cart function is done via AJAX request.
If you would like to modify this notification's content, you have to check the /design/themes/YOUR_THEME_NAME/views/checkout/components/product_notification.tpl template file. (replace the YOUR_THEME_NAME)
However I suggest you, not to write directly into a core file (both php and tpl files). You can find the official developer documentation here.
If you would like to create a controller extension for the add to cart function, you can create a controller eg. /app/addons/my_changes/controllers/frontend/checkout.post.php. Write this code into this file:
<?php
if ($mode == "add") {
//Do something here
}
If the My changes add-on is active, this code will run after the product is added to the cart, but before the tpl file is displayed.
You can create the app/addons/my_changes/controllers/frontend/checkout.post.php file with the following content:
<?php
use Tygh\Registry;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($mode == 'add') {
$added_products = Registry::get('view')->getTemplateVars('added_products');
if (!empty($added_products)) {
foreach ($added_products as $data) {
if (!empty($data['product_id']) && $data['product_id'] == THE_ID_OF_REQUIRED_PRODUCT) {
$msg = Registry::get('view')->fetch('addons/my_changes/custom_product_notification.tpl');
fn_set_notification('I', __('custom_product_notification_title'), $msg, 'I');
}
}
}
}
return;
}
then
create the "custom_product_notification_title" language variable on the Administration -> Language -> Manage translation page
create the "design/themes/YOUR_THEME/templates/addons/my_changes/custom_product_notification.tpl" template with the required content
activate the "My changes" add-on
clear the cache by adding the "?cc&ctpl" to the URL in the admin panel
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.
How can I display the $total on an external web page from opencart. The web page and opencart are on the same server but opencart is installed in a sub folder. I would like to display the Total and a link back to opencart. I have the link as follows so far:
<div id="topcart">
<p>
<span class="cartamt">$123.00</span>
<img src="/images/icon-cart.png" alt="Cart" />
</p>
</div><!-- end div topcart -->
I just need to replace the 123.00 with the actual total amount in opencart.
Thanks,
Robert Campbell
The simplest way to do this would be to save the total as getTotal() is called in the cart class to a session variable, and then use the session variable in that page (assuming they are on the same domain and using the same session). To set the session variable, use
$this->session->data['currentTotal'] = $total;
Just before return $total; in system/library/cart.php. Adding currency formatting gets a little more tricky. You instead need to use
global $registry;
$this->session->data['currentTotal'] = $registry->get('currency')->format($total);
After that, in your non OC page start a session if it's not already started, and add
<?php echo empty($_SESSION['currentTotal'] ? '$0.00' : $_SESSION['currentTotal']); ?>
In the place of your $123.00
To anyone else trying to find this answer it's simple. Edit the system/library/cart.php file like jay says but when getting the total use
$_SESSION['default']['currentTotal'] instead.