Magento custom API for adding product wishlist - magento

I am implementing the magento custom API for wishlist.
Can anybody know, how to add the wishlist.
I tried using the magento 'wishlist' module, but the product is not saving in to wishlist.
I am using the following function to save.
public function addNewItem($product, $customer_id, $buyRequest = null, $forciblySetQty = false)
{
}
I can able to get the wishlist using this post.
http://pastebin.com/G7ci0Mhu

This may help you
<?php $wishlist = Mage::getModel('wishlist/item')->load($_product->getId(),'product_id');
if($wishlist->getId())
//product is added
echo "Added! - Product is in the wishlist!";
else
//add product to wishlist
echo "<a href='".$this->helper('wishlist')->getAddUrl($_product) ."'>Add This?</a>";
;?>
Mage::getModel('wishlist/item')->load($id)->delete();
http://abhijitberadeveloper.blogspot.in/2012/07/product-add-wishlist.html
http://docs.magentocommerce.com/Mage_Wishlist/Mage_Wishlist_Helper_Data.html#methodgetWishlistItemCollection
http://docs.magentocommerce.com/Mage_Wishlist/Mage_Wishlist_Helper_Data.html#methodgetWishlistItemCollection

Related

Magento relevant product when product is added to cart

I am programming an extension which adds relevant products to the cart once you add an item to the cart. Example if you are buying a pen I am going to add paper to the cart. Bundled packages are not an option since I need to match certain conditions. I tried the following:
I set up an event listener "sales_quote_item_collection_products_after_load" scan all the products in cart and add the relevant products. Sadly you have to reload the cart in order to make the products appear.
I used this code in, my event listener, to add products to cart:
// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
// Add a product (simple); id:12, qty: 3
$cart->addProduct(12, 3);
$cart->save()
The strange thing is that removing products using the cart helper works (without refreshing):
$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();
foreach ($items as $item) {
if ($item->getProduct()->getId() == $productId) {
$itemId = $item->getItemId();
$cartHelper->getCart()->removeItem($itemId)->save();
break;
}
}
Is there a way to tell Magento to "requote" or what would you recommend? I also thought of adding the product, at the add to cart listener. But in that case I will need to implement it as well on update and remove, so it will work correctly. Using sales_quote_item_collection_products_after_load after load seemed to be the best option, since I have everything in one place.
You need to change in your code
$product_model = Mage::getModel('catalog/product');
$product_id =35;
$my_product = $product_model->load($product_id);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$cart->addProduct($my_product, array('qty' => 1));
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

Add product short-description on product review page in magento

I am using
$_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description');
in catalog/product/view.phtml to show the product short description.
It is showing in single product page but not in product review page though enabling Template Path Hints shows they both come from view.phtml
Any suggestions?
There are some logical implementation avalibale on magento.
I have seen in class Mage_Review_Block_Product_View the short description is set as null .
I have comment that code .Now it working
So copy app/code/core/Mage/Review/Block/Product/View.php
to app/code/local/Mage/Review/Block/Product/View.php
and edit
protected function _toHtml()
{
$this->getProduct()->setShortDescription(null);
return parent::_toHtml();
}
to
protected function _toHtml()
{
//$this->getProduct()->setShortDescription(null);
return parent::_toHtml();
}
Or Enable short_description to used in product list from Admin>Catalog>Manage Attribute

How to show product custom options in checkout/cart page

I want show custom options on cart page i tried using $_options = $this->getOptionList() but it only shows the selected option only , i want to retrieve all options.
To get product custom option value at cart page which are set at 'AddtoCart' time try with following code.
$cart = Mage::helper('checkout/cart')->getCart()->getQuote()->getAllItems();
/* cart item loop */
foreach($cart as $item) {
/* This will get custom option value of cart item */
$_customOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
/* Each custom option loop */
foreach($_customOptions['options'] as $_option){
echo $_option['label'] .'=>'. $_option['value']."<br/>";
// Do your further logic here
}
}
Already replied at
Display Magento Custom Option Values in Shoping Cart
You can get only selected options from using this function $this->getOptionList(), but if you actually want to retrieve all custom options then first of all you need to retrieve product id
You can get product like this on cart page
$_item = $this->getItem();
$_item->getProduct();
This will retrieve product from this you can get product and load product.
$product = Mage::getModel('catalog/product')->load($_item->getProduct()->getData('entity_id'));
$product = Mage::getModel('catalog/product')->load($product);
foreach ($product->getOptions() as $o) {
print_r($o); // show all product options
}
}

How to add Rating of a product in products listing?

I am displaying products of a particular category to the homepage content section.
I have made a separate .phtml file to display my homepage.
Now I want to show the ratings of a product (products are already rated). How do I show it?
If you look at the category listing template it's pretty easy to work out how category pages render out the review summary to show the rating block.
First load the product in question:
$product = Mage::getModel('catalog/product')->load($id);
Then create a product listing block to give access to the correct methods:
$block = Mage::app()->getLayout()->createBlock('catalog/product_list');
Finally run the getReviewsSummaryHtml() method and pass it the product to get the summary HTML.
$html = $block->getReviewsSummaryHtml($product, 'short');
You can do this.
$_product = Mage::getModel('catalog/product')->load($id);
if ($_product->getRatingSummary() && $rating = $this->getReviewsSummaryHtml($_product, 'short')) :
echo $rating;
else:
echo "<a href='$_product->getProductUrl()'>" . $this->__('Be the first to review this') . "</a>";
endif;

To disable url for particular subcategory in magento cart

just got handed a magento site to update. No experience with the cart, so I hope these questions aren't too simplistic. Did search around a bit and haven't been able to find straightforward answers
=> For Some of my accessories showing in magento cart i does not want link on their title and image so how i made this dynamically.
Any help is appreciable
I have create a function in /app/code/core/Mage/Checkout/Block/Cart/Item/Renderer.php
public function getCustumcatId()
{
$proid=$this->getProduct()->getId();
$categoryIds=$this->getProduct()->getCategoryIds($proid);
foreach($categoryIds as $categoryId)
{
$category = Mage::getModel('catalog/category')->load($categoryId);
}
return $category->getName();
}
and call it on default.phtml of cart
after getting name i use if and else to remove link thanks for help and comment

Resources