How i can get quantity of whole cart in file cart.php, i search somethings like in tpl {$cart_qties}
thx for answer
If you ask about Classes/Cart.php there is:
/** * Return cart products quantity
* * #result integer Products quantity */
public function nbProducts() { if (!$this->id) { return 0; } return Cart::getNbProducts($this->id); }
pls edit it is hard paste code on phone ;-)
Related
I have used the sorting by ->setOrder('price','desc');
but in this case its not working well when we sort the products by name
Is there any way to sort by price (from lower to bigger) in such way, that products with zero price will bein the end of the list???
public function setCollection($collection)
{
$this->_collection = $collection;
$this->_collection->setCurPage($this->getCurrentPage());
// we need to set pagination only if passed value integer and more that 0
$limit = (int)$this->getLimit();
if ($limit) {
$this->_collection->setPageSize($limit);
}
if ($this->getCurrentOrder()) {
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection())
->setOrder('price','desc');
}
return $this;
}
The question not very clear, yet from what I understand:
(Price Sorting) This feature is provided by default in Magento in Product Listing Pages.
Maybe you have changed the price attribute # backend.
Check for price attribute.
Used in Product Listing = Yes
Used for Sorting in Product Listing = Yes
Clear Cache, and you should be ready to go.
i want to add custom donate(like tip) module in addition to product price
suppose Product A (price 100) have text box field
1:donate with blank value which user have to enter user can insert any value and product price will be donated value + product price
how can i implement this via observer
i tried using "checkout_cart_product_add_after" observer
code of observer.php
class Mour_Customgroup_Model_Observer
{
public function modifyPrice(Varien_Event_Observer $obs ){
// Get the quote item
$quote = $obs->getEvent()->getQuote();
$item = $obs->getQuoteItem();
$product_id=$item->getProductId();
$_product=Mage::getModel('catalog/product')->load($product_id);
$newprice=$_product->getPrice()+10;
Mage::log('My log entry', null, 'mylogfile.log');
// Set the custom price
$item->setCustomPrice($newprice);
$item->setOriginalCustomPrice($newprice);
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
}
}
but this code adds same amount to add items in cart
my issue are
how to pass value of donate text box to observer
add donated value to product price
I'm working on a project where the entire store products have a special price different (lowered) from the original price.
I want to be able to apply shopping cart discounts By Percentage of the Original Price just like Catalog Discount Price Rules does.
Right now, if I apply a shopping cart “Percentage of product price discount” rule, it will apply the discount to the special price instead of the original price.
Where is the function for Shopping Cart Rules at? Any details on modifying it to apply discounts on original price will be appreciated.
I recently had to solve the same problem. These two blog guides were very helpful in crafting my final solution.
My custom observer on the salesrule_validator_process event looks like this:
class My_SalesRule_Model_Observer
{
// New SalesRule type
const TO_ORIGINAL_PRICE = 'to_original_price';
/**
* Add the new SalesRule type to the admin form.
* #param Varien_Event_Observer $obs
*/
public function adminhtmlBlockSalesruleActionsPrepareform($obs)
{
$field = $obs->getForm()->getElement('simple_action');
$options = $field->getValues();
$options[] = array(
'value' => self::TO_ORIGINAL_PRICE,
'label' => Mage::helper('salesrule')->__('Percent of original product price discount')
);
$field->setValues($options);
}
/**
* Apply the new SalesRule type to eligible cart items.
* #param Varien_Event_Observer $obs
*/
public function salesruleValidatorProcess($obs)
{
/* #var Mage_SalesRule_Model_Rule $rule */
$rule = $obs->getRule();
if ($rule->getSimpleAction() == self::TO_ORIGINAL_PRICE) {
/* #var Mage_Sales_Model_Quote_Item $item */
$item = $obs->getItem();
// Apply rule qty cap if it exists.
$qty = $rule->getDiscountQty()? min($obs->getQty(), $rule->getDiscountQty()) : $obs->getQty();
// Apply rule stepping if specified.
$step = $rule->getDiscountStep();
if ($step) {
$qty = floor($qty / $step) * $step;
}
// Rule discount amount (assumes %).
$ruleDiscountPercent = $rule->getDiscountAmount();
/* #see My_Catalog_Model_Product::getDiscountPercent */
$productDiscountPercent = $item->getProduct()->getDiscountPercent();
// Ensure that the rule does not clobber a larger discount already present on the $cartItem.
// Do not apply the rule if the discount would be less than the price they were already quoted
// from the catalog (i.e. special_price or Catalog Price Rules).
if ($ruleDiscountPercent > $productDiscountPercent) {
// Reduce $ruleDiscountPercent to just the gap required to reach target pct of original price.
// In this way we add the coupon discount to the existing catalog discount (if any).
$ruleDiscountPercent -= $productDiscountPercent;
$pct = $ruleDiscountPercent / 100;
// Apply the discount to the product original price, not the current quote item price.
$discountAmount = ($item->getProduct()->getPrice() * $pct) * $qty;
$item->setDiscountPercent($ruleDiscountPercent);
$obs->getResult()
->setDiscountAmount($discountAmount)
->setBaseDiscountAmount($discountAmount);
}
}
}
}
If you have set up your extension properly, you should see the new rule type appear under:
Promotions -> Shopping Cart Price Rules -> Edit 'New Rule' -> Actions -> Update prices using the following information: Apply [Percent of original product price discount]
Caveats: you’ll notice I implemented this to work on percentages, including creating a method on the product model to calculate the catalog discounted price (i.e. special price and other discounts applicable at the catalog level). You will need to implement that if you wish to do the same, or update this logic to fit your scenario perhaps just referring to $item->getProduct()->getPrice() instead.
I am using following code to get the customers who are having products in their wishlist
$wishlist = Mage::getModel('wishlist/wishlist')->getCollection();
$wishlistCustomers = array();
foreach($wishlist as $wish)
{
$wishlistCustomers[] = $wish->getCustomerId();
}
print_r($wishlistCustomers);
But it is also giving me the customers who does no have products in the wishlist.
Please suggest
You can use getItemsCount() method of the wishlist model to check if a wishlist has any items in it.
...
foreach($wishlist as $wish)
{
if($wish->getItemsCount() > 0){
$wishlistCustomers[] = $wish->getCustomerId();
}
}
print_r($wishlistCustomers);
I have created a custom product grid using the varien grid functionality and am using it as an order form. Basically, there is a Product Name, Product Price, and an input field for the user to enter the amount of a product they would like.
There are thousands of products, and I need to give a running subtotal of what the user has selected.
The closest I've gotten is as adding the following to Grid.php...
protected function _afterLoadCollection()
{
$collection = $this->getCollection()->load();
$total = 0;
if ($collection) {
foreach($collection as $item) {
$itemPrice = $item->getPrice();
$itemQty = $item->getQty();
$total = $total + ($itemPrice * $itemQty);
}
echo $total;
}
}
However, the results are affected by the current limit, and therefore only totals the current page.
Is there a way around this, or a better way to get the running total of the two columns?
Thanks in advance, I've been stuck on this for days!
You can try this to clear the collection complements, and set for the first page a big limit
$_productCollection = $this->getLoadedProductCollection();
$_productCollection->clear();
$_productCollection->setPage(1,99999);