Dont remove filters in magento - magento

I Apply filter in magneto. But if I Click on any filter some filter are hide now I want to show all filter always.Any help will be appreciated.

the part of code that hides other options located at app\code\core\Mage\Catalog\Model\Layer\Filter\Attribute.php this part.
if ($filter && strlen($text)) {
$this->_getResource()->applyFilterToCollection($this, $filter);
$this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
$this->_items = array();
}
Overwrite this part in local pool.

Related

Magneto - block orders from specific state

I'm looking to restrict the ability for orders in Magento to specific states, or rather, block a specific state.
I'm selling products that I don't want local competition to be able to easily purchase.
It'd be even cooler to use some form of geo location to display a banner on the site, saying we don't allow orders from your state only if the IP seems to come from that state.
Or maybe a hack would be to use a geo location, and css hide the add to cart button if the IP was based from specific state?
any suggestions!
Thanks!
edit: I've been able to get the state like this:
but how to say "if state=X, then load this css file, which could hide add to cart, display a banner, etc."
<?php
function getClientIP(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
$ipaddress = getClientIP();
function ip_details($ip) {
$json = file_get_contents("http://ipinfo.io/{$ip}/geo");
$details = json_decode($json, true);
return $details;
}
$details = ip_details($ipaddress);
echo $details['region'];
?>
I'm against hiding a CTA button using css, what if someone just inspects the page and unhides it. I suggest you to do something similar to this.
//considering you can fetch the location using your php logic in your server side already.
$details = ip_details($ipaddress);
$loc = $details['region'];
blockedList = array(); //maintain the list of blocked states here.
if(in_array($loc,$blockedList){
//display banner, hide add-to-cart button
} else {
//display add-to-cart button
}
This magento extension wasn't easy to find for some reason, but it works!
http://www.magentocommerce.com/magento-connect/regions-manager.html

Hide text from one magento store

I have two stores created, retail and wholesale. I created a static block visible in both the stores. Without logging in, i want to hide a line when somebody opens the wholesale page using css display:none.
I need to a php code that would detect different stores so i can add css class. I've seen examples for logged in users but not for stores.
Example code that i'm looking for:
<?php
if (store = wholesale) then
else if…
end if
?>
Anyone?
use this
$storeCode = Mage::app()->getStore()->getCode();
if($storeCode == 'default')
{
/* your code here */
};
You can apply store condition as per below :
if (Mage::app()->getStore()->getId() == YOUR STORE VIEW ID HERE)
{
//apply your custom code here
}
or
if (Mage::app()->getStore()->getCode() == YOUR STORE VIEW CODE HERE)
{
//apply your custom code here
}
Apply your store id or code and put them in condition accordingly.

Importing products into Magento breaks images on existing products

After exporting, changing some details and then importing a large number of products into Magento, I noticed all the images are no longer set. The images still exist in the media gallery for each product, but they are not set as the base image.
I've seen that in some cases, you need to copy images over to a /media/import/ folder, but is it possible to change the import file so that I can keep the images where they are?
Right now, all the images appear to be in a folder: /media/catalog/product/
Any help would be very appreciated.
Additionally, if it were possible to run a script that sets all product's base image to the first image in its gallery, that would work just as well. Thanks!
Let's say that you have load the products and you are ready to make a change and save them. With this code:
if (file_exists($imagePath)) {//New image file
//Load your media table
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
try {
//Now you have all the images available for your product
//if you previously have assign anything
$items = $mediaApi->items($product->getId());
//loop them
foreach ($items as $item) {
//With that line you can remove them if you want
echo ($mediaApi->remove($product->getId(), $item['file']));
}
} catch (Exception $exception) {
var_dump($exception);
die('Exception Thrown');
}
$cache = Mage::getSingleton('core/cache');
$cache->flush();
//You need that line
$product->setMediaGallery(array('images' => array(), 'values' => array()));
//That line assigns your new image.As base,thumbail and image.
//Use it in the loop if you want to reassign an existing image.
$product->addImageToMediaGallery($imagePath, array('thumbnail', 'small_image', 'image'), false, false);
I hope that helps you
Cheers!

Don't want remove wishlist items when click 'Add all to cart' button - magento

I change in code follow this http://www.magentocommerce.com/boards/viewthread/197868/
to keep items in wishlist when user add item to cart.
But If user add all to cart instead of each item. All product will be remove from wishlist.
I want to keep it in wishlist. Have any know how to fix it?
I try to open app\code\core\Mage\Wishlist\Controller\Abstract.php and comment out lines
$item->delete();
But nothing better.
I'd appriciate your helping.
Try this,
Step 1:
While adding allitems from wishlist to cart, there is no way to rewrite abstract file. so copy the file from
app\code\core\Mage\Wishlist\Controller\Abstract.php
to
app\code\local\Mage\Wishlist\Controller\Abstract.php
Then find inside Abstract.php
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->getProduct();
}
set $isOwner to false.Update the code as
$isOwner = false;
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->getProduct();
}
Step 2:
While adding individual items from wishlist to cart.
Follow the below steps
Rewrite the Mage_Wishlist_IndexController to local codepool
Then find the code in the rewrited controller file
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->getProduct();
}
Update the code as
$isOwner = false;
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->getProduct();
}
Now wislist items will retain even after add to cart.
Refer this link
Tought about that too, but figured out that the deletion happens on line 108 in Mage_wishlist_Controller_Abstract
// Add to cart
if ($item->addToCart($cart, $isOwner)) {
$addedItems[] = $item->
}
In your Wishlist the $isOwner is set to true and that's the reason why your items get removed.
set $isOwner is set to false to stop the items get removed
The way I solved this instead of overwriting or editing a abstract core file like some comments suggest I instead did a rewrite of the Wishlist controller:
Mage/Wishlist/controllers/IndexController.php
If you look in the cartAction function on you will find the following line $item->addToCart($cart, true);. The second parameter being sent here decides if the item should be deleted from the wishlist or not. If you in your rewritten controller set this to false the items will persist in the wishlist even though you add them to your cart.

Hide a group in catalog product?

Please help me if anybody know how this work can be done.
I want to hide the website tab in catalog Product, but its functionality should exist. That is, I have made all the check boxes automatically checked,so i dont want to show this tab anybody...but at the time of adding product..check boxes values would be saved.
Not exactly sure how you would do this, but basically you need to bind an Observer in the adminhtml render sequence that calls Mage_Adminhtml_Block_Widget_Tabs::removeTab($tabId) where $tabId is the Id of the websites tab (I think it's just "websites"). The trick is to find the right event to bind your Observer to, #Joseph's list of events should get you started. I would try something like adminhtml_block_html_before.
Your observer would also set the values on the product at the same time.
Good luck,
JD
In ProductController.php
Websites
*/
if (!isset($productData['website_ids'])) {
$productData['website_ids'] = array();
}
$productData['website_ids']=$this->getStoreWebsiteId(); //newly added
//newly added
public function getStoreWebsiteId(){
$selectWebsite="SELECT * from core_website WHERE website_id!=0";
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$value=$connection->fetchAll($selectWebsite);
foreach($value as $websiteDetails){
$websiteId[]=$websiteDetails['website_id'];
}
return $websiteId;
}

Resources