I met with a requirement for my magento project, according this I need to provide special discount to specific customer group on their purchase. This discount must be shown in customer account,if they belong to that particular group, and when user want to use that particular discount, price of that item must be discounted according to that discount offer to them.
I know how to create a customer group, but how can I give them desired discount and make it show at time of purchase. so that customer can use it.
please suggest me any method or refer any document.
Thanks!
Since you want a discount to show "at time of purchase", use a Shopping Cart Price Rule from the Promotions menu. It can be restricted to certain customer groups.
A customer's group can be set by editing their account from Customers > Manage Customers menu, then look in Account Information for the Customer Group control.
The links I gave are both from the Magento User Guide. Please read it all.
http://www.magentocommerce.com/wiki/welcome_to_the_magento_user_s_guide/welcome_to_the_magento_user_s_guide
<?php
/**
* Get the resource model
*/
$resource = Mage::getSingleton('core/resource');
/**
* Retrieve the read connection
*/
$readConnection = $resource->getConnection('core_read');
/**
* Retrieve current users groupId
*/
$currentUserGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
/**
* Creating the custom query to fetch coupons
*/
$query = '
SELECT sr.rule_id, sr.name, sr.is_active, src.code, src.expiration_date
FROM `salesrule` sr
JOIN `salesrule_coupon` src ON (sr.`rule_id` = src.`rule_id`)
JOIN `salesrule_customer_group` scg ON(scg.`rule_id` = src.`rule_id`)
where scg.customer_group_id = '.$currentUserGroupId.'
AND sr.is_active = 1
AND ( ( src.expiration_date is null ) or ( src.expiration_date > now() ) )
';
//store result set in $rules
$rules = $readConnection->fetchAll($query);
// $rules will contain the array of all the coupons available to the current user
// This array contains all the data required
print_r($rules);
?>
Related
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.
I need to be able to get the discount type applied in the cart.
I can get the discount amount like so:
$cart = Mage::getModel('checkout/cart')->getQuote();
$totals = $cart->getTotals();
$discount = $totals["discount"]->getValue();
How can i check what type of discount it is - whether it is a percentage or fixed amount off?
Take a look at applied_rule_ids in sales_flat_quote and sales_flat_quote_item
You could try something like
//if the item has not had a rule applied to it skip it
if($item->getAppliedRuleIds() == '')continue;
/*
* I cant remember in the database they might be comma separated or space if multiple rules were applied
* the getAppliedRuleIds() function is the one you want
*/
foreach(explode(",",$item->getAppliedRuleIds()) as $ruleID){
//Load the rule object
$rule = Mage::getModel('catalogrule/rule')->load($ruleID);
// Throw out some information like the rule name what product it was applied to
echo "<p>".$item->getSku()." had rule ".$rule->getName()."(".$item->getAppliedRuleIds().") applied </p>";
}
See Magento - get price rules from order
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);
I am using following tutorial to display the most sold product sort by option(Filtering) to display on product listing page in magento?
Tutorial
/app/code/local/Mage/Catalog/Model/Resource/Product/collection.php
<?php
public function sortByReview($dir){
$table = $this->getTable('review/review');
$entity_code_id = Mage::getModel('review/review')->getEntityIdByCode(Mage_Rating_Model_Rating::ENTITY_PRODUCT_CODE);
$cond = $this->getConnection()->quoteInto('t2.entity_pk_value = e.entity_id and ','').$this->getConnection()->quoteInto('t2.entity_id = ? ',$entity_code_id);
$this->getSelect()->joinLeft(array('t2'=>$table), $cond,array('review' => new Zend_Db_Expr('count(review_id)')))
->group('e.entity_id')->order("review $dir");
}
?>
But I want to sort products which are most sold from every category.
How can I do this?
Is there any free extension available for this?
I did the following thing as the client did not want automatically filter most sold product.
I created an attribute "popular" as drop down and give values from 1 to 5.Then marked "Used for Sorting in Product Listing" to Yes.
After this the attribute was visible under sorting options.
Let's say a customer is in group A and for the group A a final price of a product is 10$. Now, in a module I need to find out what price he would get if he was in another group B. Is it possible?
I have used the following solution after some digging in Mage. Please let me know if this solution is problematic (so far it is working well though). Given a quote item:
$product = $quoteItem->getProduct();
$qty = $quoteItem->getQty();
$product->setCustomerGroupId($targetGroup->getId());
$price = $product->getPriceModel()->getFinalPrice($qty, $product);