Minimum total of items in shopping cart to allow checkout - magento

I'm trying to find a configuration that allows one of my customer groups (wholesale) to add any given number of items to their shopping carts, but have a restricted checkout equal or greater than 16 items in total.
For example:
8 items from product A
2 items from product B
6 items from product C
That would be a total of 16 items and it would be possible for them to checkout.
I tried configuring the Minimum Qty Allowed in Shopping Cart, but then, they have to get 16 items of each product.
Do you know if there is a way to configure, add an extension or hardcode something to solve this problem?
Thank you for your time!

Easiest way is to set a minimum order amount
/admin/system_config/edit/section/sales
To implement a minimum item restriction, you can place an observer to fire on one page checkout which checks the item quantity it cart and redirects you back to the cart if its below your threshold with a message.
Full prototype, flavor as needed:
app\etc\modules\Spirit_Cms.xml
<?xml version="1.0"?>
<config>
<modules>
<Spirit_Cms>
<active>true</active>
<codePool>local</codePool>
</Spirit_Cms>
</modules>
</config>
app\code\local\Spirit\Cms\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Spirit_Cms>
<version>0.0.1</version>
</Spirit_Cms>
</modules>
<frontend>
<events>
<controller_action_predispatch_checkout_onepage_index>
<observers>
<spirit_cms_restrict_checkout>
<class>Spirit_Cms_Model_Observer</class>
<method>restrictCheckout</method>
</spirit_cms_restrict_checkout>
</observers>
</controller_action_predispatch_checkout_onepage_index>
</events>
</frontend>
<global>
<models>
<spirit_cms>
<class>Spirit_Cms_Model</class>
</spirit_cms>
</models>
</global>
</config>
app\code\local\Spirit\Cms\Model\Observer.php
<?php
class Spirit_Cms_Model_Observer
{
public function restrictCheckout( $oObserver )
{
// Ensure we only observe once.
if( Mage::registry( 'restrict_checkout_flag' ) )
{
return $this;
}
else
{
$oQuote = Mage::getSingleton( 'checkout/cart' )->getQuote();
$oCartItems = $oQuote->getAllItems();
$iTotalQty = 0;
foreach( $oCartItems as $oCartItem )
{
$iTotalQty = $iTotalQty + $oCartItem->getQty();
}
if( $iTotalQty < 12 )
{
$oSession = Mage::getSingleton( 'checkout/session' );
$oSession->addError( 'Please add at least 12 items to your cart.' );
Mage::app()->getResponse()->setRedirect( Mage::getUrl( 'checkout/cart' ) );
}
Mage::register( 'restrict_checkout_flag', 1, TRUE );
}
}
}
?>

Related

Magento observer - after/before order place

In my website there is a product having qty as 500 (For Example), if a user ordered 600 qty the payment must process for available and remaining 100 qty must get paid after the stock avail. At present user can only pay for 500 qty.
Can anybody help to update the qty to 600 after placing an order programmatically? So that admin can manage invoice/shipment for first 500 qty and after user pay for the 100 again invoice/shipment.
Any other option to manage this?
Current observer code (not working):
public function myfucn($observer){
$data = $observer->getEvent()->getOrder();
$id = '40';
$qty = 600;
$_product = Mage::getModel('catalog/product')->load($id);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$cart->addProduct($_product, array('qty' => $qty));
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);}
Config.xml
<modules>
<Ajt_PlaceOrder>
<version>0.0.1</version>
</Ajt_PlaceOrder>
</modules>
<global>
<models>
<placeprder>
<class>PlaceOrder_Model</class>
</placeprder>
</models>
<events>
<sales_quote_save_before>
<observers>
<ajt_placeorder_model_observer>
<class>Ajt_PlaceOrder_Model_Observer</class>
<method>mymethod</method>
</ajt_placeorder_model_observer>
</observers>
</sales_quote_save_before>
</events>
</global>
The above observer code im trying is to add product to cart. But if you have solution to update the qty of already existed item at cart before place an order please guide me.

Limit number of images per product - Magento

Does anyone know how to Limit the number of images per product that can be uploaded to - Magento? Say I only want to allow 6 images per product.
Thanks,
public function saveAction()
{
/* START: Handle the max images per product */
$data = $this->getRequest()->getPost();
$images = Mage::helper('core')->jsonDecode($data['product']['media_gallery']['images']);
if($totalImages = count($images)) {
$maxPhotoPerProduct = 5;
if($totalImages > $maxPhotoPerProduct) {
Mage::getSingleton('core/session')->addError($this->__('Max. number of images per product reached, extra images have been removed'));
}
$_allowedImages = array_slice($images, 0, $maxPhotoPerProduct);
//Return the allowed images back to the $_POST
$_POST['product']['media_gallery']['images'] = Mage::helper('core')->jsonEncode($_allowedImages);
}
/* END: Handle the max images per product */
//Zend_Debug::dump(Mage::helper('core')->jsonDecode($_POST['product']['media_gallery']['images'])); exit;
//Run standard saveAction()
parent::saveAction();
}
Note that code above is from my Mycompany_Mymodule_Adminhtml_Catalog_ProductController class located in the “app/code/local/Mycompany/Mymodule/controllers/Adminhtml/Catalog/ProductController.php” file.
Meaning I overwrote the default “app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php” controller by using the syntax shown below in Mymodule config.xml file.
</config>
...
<admin>
<routers>
<adminhtml>
<args>
<modules>
<sintax before="Mage_Adminhtml">Mycompany_Mymodule_Adminhtml</sintax>
</modules>
</args>
</adminhtml>
</routers>
</admin>
...
</config>

Magento store wise Invoice Increment Id group

I have total 10 multi-store in a single domain, when customer ordering from different store invoice increment Id and Prefix is creating different. but I want only two different invoice type, prefix "1" for store id 6 and all other store prefix's should be same like '19' and all increment id should be same.
10 different store but invoice should be only two types.
Is there any good solution, highly appreciated.
thanks
You are require to follow below steps to do this:
1) - In the /Namespace/Module/etc/config.xml you have to write the following thing:
<config>
<modules>
<Namespace_Module>
<version>0.1.0</version>
</Namespace_Module>
</modules>
<global>
<models>
<eav>
<rewrite>
<entity_store>Namespace_Module_Model_Entity_Store</entity_store>
</rewrite>
</eav>
</models>
</global>
</config>
2) - Register module in magento module list under app/etc/modules/Namespace_Module.xml
<config>
<modules>
<Namespace_Module>
<active>true</active>
<codePool>local</codePool>
<depends />
</Namespace_Module>
</modules>
</config>
3) - You have to copy the same code under /Mage/Eav/Model/Entity/Store.php into your file under /Namespace/Module/Model/Entity/Store.php.
4) Edit your Store.php file: Please find below code
public function loadByEntityStore($entityTypeId, $storeId)
{
$this->_getResource()->loadByEntityStore($this, $entityTypeId, 1);//1 is your default store_id
return $this;
}
Replace it with below code
public function loadByEntityStore($entityTypeId, $storeId)
{
$this->_getResource()->loadByEntityStore($this, $entityTypeId, 1);//1 is your default store_id
return $this;
if($storeId==6){//6==StoreID
$this->_getResource()->loadByEntityStore($this, $entityTypeId, 1);//1 is your default store_id
}else{
$this->_getResource()->loadByEntityStore($this, $entityTypeId, 19);
}
}
Hope this will work for you. :)
Best of luck.
Below is the solution for all Store view. In this solution all store Ids will be same.
Find in app/code/mage/sales/model/entity/setup.php the following piece of code:
'invoice' => array(
'entity_model' => 'sales/order_invoice',
'table' =>'sales/order_entity',
'increment_model' =>'eav/entity_increment_numeric',
'increment_per_store'=>false,
and chance
'increment_per_store'=>false
To
'increment_per_store'=>true

magento how to change cart account in checkout page

in product detail page, the product price is 50 dollar, I use JavaScript change the price to 80 dollar, but when add to cart, it is still 50 dollar in checkout page. how to let it still 80 dollar in checkout page?
You need use "sales_quote_add_item" magento event to update the product price in cart session.
You have to make a custom module for that purpose.
Create a file in app/etc/modules/Company_All.xml
<?xml version="1.0"?> <config> <modules>
<Company_Product>
<codePool>local</codePool>
<active>true</active>
</Company_Product> </modules> </config>
Create configuration file for our module file in app/code/local/Company/Product/etc/config.xml
<?xml version="1.0"?> <config> <global>
<models>
<product>
<class>Company_Product_Model</class>
</product>
</models>
<events>
<sales_quote_add_item><!--Event to override price after adding product to cart-->
<observers>
<company_product_price_observer><!--Any unique identifier name -->
<type>singleton</type>
<class>Company_Product_Model_Price_Observer</class><!--Our observer class name-->
<method>update_book_price</method><!--Method to be called from our observer class-->
</company_product_price_observer>
</observers>
</sales_quote_add_item>
</events> </global> </config>
Create our observer file in app/code/local/Company/Product/Model/Price/Observer.php
class Company_Product_Model_Price_Observer{
public function update_book_price(Varien_Event_Observer $observer) {
$quote_item = $observer->getQuoteItem();
//if(){ //your logic goes here
$customprice = 50;
//}
$quote_item->setOriginalCustomPrice($customprice);
$quote_item->save();
return $this;
}
}

Magento Admin Sales > Order > Item Url

I am trying to create a link from my helpdesk software to the sales order page in the backend of magento.
Magento constructs the url as the example below where the number represents the Order ID.
/index.php/admin/sales_order/view/order_id/12394/
However, the Order Id does not equal the Order Number because credit invoices etc. are included in the count.
Is there an other way for me to link to the order page using the Order Number.
Thanks!
There are 2 types of order number in magento
Order increment id
Order id (mostly use internal in magento).
The admin uses the order id while the number on you invoice is the order increment id.
The quickest way to get around this is to create a custom module that look up order id by order increment id and the redirect to the view page using the order id.
In /app/etc/modules/MageIgniter_OrderRedirect.xml
<?xml version="1.0"?>
<config>
<modules>
<MageIgniter_OrderRedirect>
<active>true</active>
<codePool>local</codePool>
</MageIgniter_OrderRedirect>
</modules>
</config>
In /app/code/local/MageIgniter/OrderRedirect/controllers/RedirectOrderController.php
<?php
class MageIgniter_OrderRedirect_RedirectOrderController extends Mage_Core_Controller_Front_Action
{
public function viewAction(){
$increment_id = Mage::app()->getRequest()->getParam('id');
$order = Mage::getModel('sales/order')->loadByIncrementId($increment_id);
$order_id = $order->getId();
Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl("adminhtml/sales_order/view", array('order_id'=> $order_id)));
}
}
in In /app/code/local/MageIgniter/OrderRedirect/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<MageIgniter_OrderRedirect>
<version>0.1.0</version>
</MageIgniter_OrderRedirect>
</modules>
<frontend>
<routers>
<orderredirect>
<use>standard</use>
<args>
<module>MageIgniter_OrderRedirect</module>
<frontName>orderredirect</frontName>
</args>
</orderredirect>
</routers>
</frontend>
<global>
<helpers>
<orderredirect>
<class>MageIgniter_OrderRedirect_Helper</class>
</orderredirect>
</helpers>
</global>
</config>
url
www.site.com/orderredirect/redirectOrder/view/id/101512486

Resources