Show an image on certain products description only when customer is logged in - magento

I'm having a problem with Magento, how do I show an image on certain products description only when customer is logged in? And is it possible to access to which customer group the customer belongs to after logged in? So that if it's a regular customer he see's some image or not, if is a distributor he sees another kind of image.
I'm talking of images in the product description, has a banner in the beggining of the text, Im not talkign about product images.

You'll need to modify your themes catalog/product/view/description.phtml template as that's where the product description is output.
$customerSession = Mage::getSingleton('customer/session');
$customer = $customerSession->getCustomer();
if ($customerSession->isLoggedIn()) {
// your image actions here
}
if ($customer && $customer->getCustomerGroupId() == 5) {
// your customer group specific actions
}
The first if statement checks if the user is logged in, the second checks if the customer group ID is equal to 5 (or whatever customer group you're searching for.) Place this before your description to output the necessary image / content.

Related

How to show region specific products magento?

how to show products in Magento based on selected state and city? is
there any extension available for this feature? or how can i achieve
this?
You can add one (city) or two (state and city) attributes in product model (by back-office panel).
Your news attributes can be contain the list (in example string with delimiter commas) with the list of state/city where the product is allowed to be sell.
For retrieve your state/city allowed list you can :
<?php
// id product is 12345
// the city allowed list attribute code is 'city_list'
$id = 12345;
$product = Mage::getModel('catalog/product')->load($id);
$cityList = $product->getAttributeText('city_list');
var_dump($cityList);
Output something like this :
string(38) "Los Angeles, New Delhi, Caen, etc, etc"
It's possible that you may be add ->getAttributeToSelect('city_list') after load($id) if the attribute isn't retrieve by catalog/product model.

Using Magento API to add all products to root category

I want to set all the products to the root category (next to the current category they are in).
I know the best way to do this is using the Magento API, but can somebody get me started on this?
Just to be clear, i don't want to change the category id, i just want to add another category id to the product.
EDIT
It takes a lot time to check all 3000+ products to see in what other category it is. Example: Root_catId = 175 Product_1 cat = 3 (needs to be: 3, 175) Product_2 cat = 9 (needs to be: 9, 175)
You can do this without using the API but if you want to use the API try following.
You can use following first you need to create a user with permissions to access soap requests in Magento admin
<?php
$proxy = new SoapClient('http://yourmagento/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$result = $proxy->catalogCategoryAssignProduct($sessionId, '3', '10'); // 3 is category id and 10 is product id
You can loop through every product to assign the product to a specific category.
Replace the root category id with the category id which you require.

How to get quote_id from sales order page of admin in magento?

Is it possible to get quote_id of an specific order in admin->sales->orders->view(select particular order) page ?
I want to show my custom table(which contain quote_id for an order) data in admin->sales->view(select particular order) gift option block.
Yes, the order itself has quote_id, you can retrieve it in this way:
// supposing order id is 1
$order = Mage::getModel('sales/order')->load(1);
$quoteId = $order->getQuoteId();
if you need to retrieve quote object, you can get it by:
$quoteObject = Mage::getModel('sales/quote')->load($quoteId);

Magento Bundle Product - Multiple Options with Same products. How to stop Magento from hiding the repetitive products?

I am trying to setup a bundle product within Magento. This product should allow the customer to select 4 free products to include with the bundle. These products can be all different or 4 of the same product.
For example
Free Product 1
Free Product 2
Free Product 3
A customer could select four of Free Product 1, or one of Free Product 1 & 2, with two of Free Product 3.
I am using 4 drop-down input types which each have all three Free products as options. So a customer can choose any of the three products for each Free Gift line item.
Magento is only displaying one of the drop-down select lists, I believe due to the fact that each drop-down contains the same product list.
Where would I need to look to stop Magento from checking if the product options are already listed in a previous selection?
Unless you're doing this programmatically (that is writing the code), there's no way to do this.
When Magento adds a product, it first looks into the quote / shopping cart to see if one already exists. If one does, it pulls that one and adds to the quantity. There is no way to turn this off.
Programmatically, you very manually add an item to a shopping cart. This is how...
$cart = Mage::getSingleton("checkout/cart");
foreach ($products_to_add as $product_id => $custom_options) {
$product = Mage::getModel("catalog/product")->load($product_id);
$options = new Varien_Object(array("options" => $custom_options,
"qty" => 1));
// some products may result in multiple products getting added to cart
// I beleive this pulls them all and sets the custom options accordingly
$add_all = $product->getTypeInstance(true)
->prepareForCartAdvanced($options, $product, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL);
foreach ($add_all as $add_me) {
$item = Mage::getModel('sales/quote_item');
$item->setStoreId(Mage::app()->getStore()->getId());
$item->setOptions($add_me->getCustomOptions())
->setProduct($add_me);
$item->setQty(1);
$cart->getQuote()->addItem($item);
}
}
// when done adding all the items, finally call save on the cart
$cart->save();

Add additional product price with mangento base product price

I want to add additional price with product(simple) price, I am trying to do this with the help of custom attributes. I add a custom attribute "Margin Price" and I want to add up this custom attribute value (margin price) with the base price of the product in the template file.
I am updating all product price after each 5 minutes by cron job, thats why I think I have to do add margin price with base product price by this way.
I added it successfully in product list page and in product view page, but have problem with how to add this margin price with base price in the cart and onepage checkout?
Here is the code on the product list page and same for the product detail page which works fine for me in magento 1.6.x.
$regularPrice = number_format($_product->getFinalPrice(), 2);
//echo $regularPrice = $this->getPriceHtml($_product, true
$priceWithoutComma = str_replace(",", "",$regularPrice);
settype($priceWithoutComma, "float");
$marPrice = $_product->getMarginPrice();
settype($marPrice, "integer");
$finalPrice = $priceWithoutComma + $marPrice;
echo $finalPrice.Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol();
I am doing this right way or I have to changes the whole process?
Looks like you might need to consider a different approach. The reason being that echoing the price from a template file does not modify the price of the item in any way. It simply outputs a calculation.
You'll need to learn a bit about event listeners for this one to work.
Here's a blog post of mine on how to do this.

Resources