Magneto - block orders from specific state - magento

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

Related

Dont remove filters in 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.

Laravel 5: How can a dropdown be showing the selected value that the page loads initially

I'm using Laravel and I have a dropdown which fills its options from the database on load page and another text field.
Then on the submit I validate the text field to avoid empty entries, the validation is based on the request validator from Laravel. The validation is made correctly.
The problem is that when the validation is completed (it doesn't submit because i keep the text field empty) it returns to the page, but the dropdown remains selected with the last selection by the user, but in the back(sourcecode), its selected the original value that was loaded originally.
I want that the selectedIndex is the one original from the load page, not the last one selected. I tried with javascript but I had no luck change in it since it's already as the selectedIndex, but to the user, it still showing the other option. If I refresh manually it still showing the selected one incorrectly, I need to enter the URL manually so it shows correctly.
What could be a good approach to solve this "visual" issue?
Here is the controller code
public function update($user_id,GuardarBancoRequest $request)
{
$cuenta = user::whereId($user_id)->first();
$cuenta->nombrecompleto = Input::get('completo');
$temp = Input::get('tipo');
$cuenta->tipocuenta = Input::get('tipo');
$temp1 = Input::get('banco');
if ($temp == "1") {
$cuenta->cuentaclabe = Input::get('clabehidden');
$cuenta->cuentatarjeta = Input::get('cuentahidden');
} else {
$cuenta->cuentatarjeta = Input::get('cuentahidden');
$cuenta->cuentaclabe = Input::get('clabehidden');
}
if ( $temp1 == "10") {
$cuenta->otrobanco = Input::get('otro');
$cuenta->banco = "10";
} else {
$cuenta->banco = Input::get('banco');
$cuenta->save();
}
return Redirect::route('bancos.show',array(Auth::user()->id));
}
The dropdown that I'm referring is the [tipo] one
It's hard to presume without getting a chance to look at your code, but it sounds like when you do a redirect after validation you have something like
return redirect()->back()->withInput(); which causes fields to be prepopulated with the values entered earlier on the page. Remove withInput() portion in your controller if you have this.
Otherwise please mind posting your code in addition to your question, that would be helpful. (the controller part with the redirection and the view where you have the dropdown)

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.

Magento - How to show the same images for product bundles?

I created a bundled product following the instructions on the Magento site to enable it to have several sizes. See attached image:
I'm supposing that when I do the Quick simple product creation, it doesn't automatically add the same images. But since the option is only for size, the image should be the same.
The problem is, when I go to the cart or checkout page or any other page, there is no image for the product. The combination of my products with the sizes, that s over 230 products, so re-uploading all the images is a nightmare.
Question is, how can I have the system use the same image for all the different sizes?
Thanks.
I had similar problem with configurable products. I wanted the image which I assign to the main product to be added also to all options. So I created an extension and observed catalog_product_save_after event. Then I added this kind of code in my observer:
$product = $observer->getEvent()->getProduct();
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
{
$main_image = $product->getImage();
if($main_image != "no_selection")
{
$productTypeIns = $product->getTypeInstance(true);
$childIds = $productTypeIns->getChildrenIds($product->getId());
$importDir = Mage::getBaseDir('media') . DS . 'catalog/product';
foreach ($childIds as $childId)
{
foreach($childId as $_childId)
{
$childProduct = Mage::getModel('catalog/product')->load($_childId); //You get your child products here
if ($childProduct->getImage()=="no_selection")
{
$childProduct->addImageToMediaGallery($importDir.$main_image,array ('image','small_image','thumbnail'),false,false);
$childProduct->save();
}
}
}
}
}

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