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.
Related
The current Woocommerce setup of this website is being provided with a main product image and several gallery images as normal. The main product image is being used correctly so that it is shown within a list and once clicked, the product page is opened. However, within this product page, the gallery images that are provided on Woocommerce are being shown as full size images beneath each other on the right side of the screen. Within each product page there is mCustomScrollbar in action so that clients can scroll down the images. I want those to be small images with a lightbox and zoom technique instead of full size images. I have also tested plugins to see whether there are issues with regards to this however none have resulted.
I have created a new local site to test and created a product from scratch to match the original Woocommerce files with these ones since this has gone through a different developer. The following files, which seem to be in direct relation with each product page, are binary equal: product-thumbnails.php, product-image.php, single-product.php, content-product.php and content-single-product.php and therefore no changes were made in these that reflect in each product page. I have also found and optimized the below code put in functions.php however to no avail.
add_action('woocommerce_shop_loop_item_title','wps_add_extra_product_thumbs', 5);
function wps_add_extra_product_thumbs() {
if (is_product()) {
global $product;
$attachment_ids = $product->get_gallery_image_ids();
echo '<div class="product-thumbs">';
foreach( array_slice( $attachment_ids, 0,3 ) as $attachment_id ) {
$thumbnail_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail' )[0];
echo '<img class="thumb" src="' . $thumbnail_url . '">';
}
echo '</div>';
}
}
I have already put my head around this and found myself in a loop, however the above is what I have come up with, which up until now is not a solution. I want the product to show similar to this: https://www.wpstud.io/wp-content/uploads/2016/05/product-with-thumbs.jpg . The client's website is fully functional and through the busiest days of the year so I require the most efficient solution without making any major changes. Thanks so much in advance.
In addition to the above code previously provided, I have edited some small details from it and also included the Flexslider 2 by implementing the slider's javascript, creating <li> tags within the foreach loop attached with the data-thumb technique (a Flexslider speciality). The Flexslider automatically notes the <div> tag holding all <li> tags and voila', perfect execution as intended.
Some tweaks here and there to make it work but worth it, client is super happy with this update. :)
try going to Customize -> WooCommerce -> Product catalog and change the image size there
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 want to display my custom terms from tags, even the code is valid in front of me but it gives the fatal error i use this code
<p style="width:50%;float:left;">
<?php $dataTax = get_the_term_list($post->ID, 'genre', '', ', ', '');
$dataMeta = get_post_meta($postID, 'genre', true);
if ((!empty($dataTax)) || (!empty($dataMeta))){ ?>
<span class="data-info">Genre:<span itemprop="genre"></span></span>
<?php if ($dataTax != ""){
// strip links until we're ready to use the taxonomy pages in the future
echo strip_tags($dataTax);
} else {
echo $dataMeta;
}
} ?>
</p>
"genre" is my taxonmy ,i want to dispaly their values,but it give me this type of error
Genre:
Catchable fatal error: Object of class WP_Error could not be converted to string in
Any help plz
I think that's the problem - something to do with deleting custom taxonomies when there are links in the Nav Menu which link to/are related to those now-missing taxonomies.
I read a post somewhere describing the exact problem, and this guy had spent a considerable amount of time trying to fix the problem without success. In the end he had fixed it by resetting WP back to a clean state (I assume a default database), which will of course result in complete loss of site data.
I would imagine there's a fix by delving into the database, but I've not explored this as the error I had was none-critical (on a localhost test site).
I keep on getting this problem, or related problems. Basically it happens whenever I rename a custom taxonomy or custom posts. I'm using the Custom Post Type UI plugin, and I created a load of custom posts & taxonomies. I then decided to change the name of some of the taxonomies from sentence case to lowercase, and this is where it screwed various plugins (e.g. Query Multiple Taxonomies) and the wp-menu (Appearance / menu). When I changed the name of some of the taxonomies back, everything started working ok again (although had to delete the query multiple taxonomies widget, and add it back in again).
Bottom line seems to be, once you've created your custom posts/taxonomies, don't alter them.
Deleted a menu that you had created in another theme would somehow fix it if you done this.
Kinda lame solution, but works as a charm.
Some solutions from wordpress forums.
http://wordpress.org/support/topic/catchable-fatal-error-object-of-class-wp_error-could-not-be-converted-to-string-11
Replace line
echo strip_tags($dataTax);
with
print_r($dataTax);
and if you get something like: "WP_Error Object ( [errors]......"
check is "genre" a right name of $taxonomy
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
I'm using the WordPress Shopp plugin to sell products on my WordPress site. So far I love this plugin but I'm trying to do something custom and unfortunately I'm not good enough with PHP to figure this out on my own (I've done tons of research too!).
Here is what I am trying to accomplish...
To display the product title for each individual product Shopp uses the following code to reference the product title...
<?php shopp('product','name'); ?>
What I am trying to do is reference the product name and if for example the product name says something like 'FLIR H-Series Thermal Imaging Camera' I want my code to detect whether or not the product title contains the word 'FLIR' in it and if it DOES contain the word 'FLIR' I want it to echo a FLIR logo image (let's say the URL of the image is http://example.com/images/flir.jpg). Alternatively I would want it to echo a Thermal-Eye logo image anytime the word 'Thermal-Eye' is found in the product title, etc. How could I go about modifying the code to do this?
Hopefully this make sense, thanks for any help!
<?php
$keywords = array('FLIR', 'Thermal-Eye');
foreach($keywords as $word)
{
if(preg_match('/'.$word.'/i', shopp('product','name', 'return=true')))
echo $word;
}
?>
UPDATE: If you want to echo out a unique image based on the word, rather than the word itself, you can do something like:
if(preg_match('/'.$word.'/i', shopp('product','name', 'return=true')))
echo '<img src="'.get_bloginfo('stylesheet_directory').'/images/'.$word.'.jpg" />';
So in the case of FLIR, you just need to make sure FLIR.jpg exists within the images folder in your theme directory.
Best thing to do is to play around with it and see what works for you.