codeigniter shopping cart is not saving decimal qty value - codeigniter

codeigniter shopping cart is not saving decimal qty value, If the user inputs 2.5 as qty it accepts as 25. so how to make qty as double or float type.
in side cart system library i have changed
$items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty']));
to
$items['qty'] = trim(preg_replace('/([^0-9\.])/i', '', $items['qty']));
but nothing changed. please i need help!

I suggest you don't use it because it is DEPRECATED
https://www.codeigniter.com/userguide3/libraries/cart.html
you can see in this link

Related

load product using custom attribute as well as if product qty is greater then 0 in magento?

Am trying to do special offers to my magento shop.Actually that is easy but actually my scenario is differs from others.My scenario is,I must get the products based on custom attribute(date of sale) and as well as product qty must be greater than zero(Qty>0).I got the products using custom attribute like,
<?php
$collection = Mage::getResourceModel('catalogsearch/advanced_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')- >getProductAttributes())
->addMinimalPrice()
->addStoreFilter();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
$collection->addAttributeToFilter('date_sale', array('lt' => $todayDate));
return $collection;?>
On this i got the products based on date of sale is lesser than today date.On that itself i must get products which qty is greater than 0.
give me some hopes guys?
After the filter use another addAttributeToFiler('attribute code of inventory quantity',array('gt' => 0));
This acts as AND filter
You can check 'and' and 'or' filter here OR and AND STATEMENT addAttributeToFilter magento asnd use according to requirement.

Add additional product price with mangento base product price

I want to add additional price with product(simple) price, I am trying to do this with the help of custom attributes. I add a custom attribute "Margin Price" and I want to add up this custom attribute value (margin price) with the base price of the product in the template file.
I am updating all product price after each 5 minutes by cron job, thats why I think I have to do add margin price with base product price by this way.
I added it successfully in product list page and in product view page, but have problem with how to add this margin price with base price in the cart and onepage checkout?
Here is the code on the product list page and same for the product detail page which works fine for me in magento 1.6.x.
$regularPrice = number_format($_product->getFinalPrice(), 2);
//echo $regularPrice = $this->getPriceHtml($_product, true
$priceWithoutComma = str_replace(",", "",$regularPrice);
settype($priceWithoutComma, "float");
$marPrice = $_product->getMarginPrice();
settype($marPrice, "integer");
$finalPrice = $priceWithoutComma + $marPrice;
echo $finalPrice.Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol();
I am doing this right way or I have to changes the whole process?
Looks like you might need to consider a different approach. The reason being that echoing the price from a template file does not modify the price of the item in any way. It simply outputs a calculation.
You'll need to learn a bit about event listeners for this one to work.
Here's a blog post of mine on how to do this.

How to get Product id using Super attribute in Magento?

I am working on ajax module for Shopping cart in Magento. Consider i have a configurable product with 2 simple products configured as its two sizes (Small an Medium). When user selects and adds the item to cart, i cannot see the specific product id (small) in the url.
But instead supper_attribute is posted to my controller.
Is it possible for me to get the actual product id of size "Small" with the super attribute.
Below is my supper attribute array
[super_attribute] => Array
(
[129] => 128
)
129 = attribute_id (Size)
128 = attribute value (Small)
Please suggest me in this scenario. Please let me know if my question is not clear.
Thanks
Try this:
$childProduct = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($request->getData('super_attribute'), $product);
Where $product is the configurable product object.
For the Class Reference

Magento rounds up the custom product price

I'm setting a custom price depending on each customer. Using a webservice I receive the specific price for each customer in the format: XX,DD
When I use the function setprice in order to set the new price for the product:
$product->setFinalPrice($price);
Magento rounds up the price and, for example, if the $price is 38,50, then it sets the product price to 38. I've tried changing the ',' for '.' with str_replace, but in this case, it seems it can't set up the price.
How can I tell Magento to use the decimals as well?
Thanks
First you should convert your price to decimal number:
$value="38,50";
$amount = Zend_Locale_Format::getNumber($value,array('locale'=>'nl_NL'));
// or you can use str_replace
In Magento products has two types of standard price:
$product->getPrice();
$product->getSpecialPrice();
finalPrice - it is not actually product value, it will be calculated by Magento based on price, special_price, tier price and so on. You should set price value and save the product:
$value = "38,50"; //this decimalformat is used in nl_Nl locale
$amount = Zend_Locale_Format::getNumber($value,array('locale'=>'nl_NL'));
$amount = Mage::app()->getStore()->roundPrice($amount); //round price based on Magento logic
$product->setPrice($amount); //price - is actual value of product
// some extra code here
$product->save();
I'll throw in that you can use:
echo number_format($_product->getPrice(), 2)
It will give you a couple of decimal places.
I am guessing you do not want the price to round up. If that is the case then your solution depends on the version of PHP you are using.
PHP 5.3 you can simply use the round function to round it down like so:
round($price, 2, PHP_ROUND_HALF_DOWN);
If you are using PHP 5.2 you do not have the luxary of the PHP_ROUND_HALF_DOWN so you have to put the following function in somewhere (a helper makes the most sense to me) and call it:
floor($line_item_price * 100) / 100;
What this does is first multiply the value with 100 and then floor the value. This gives you a rounded down value with the precision of 2. Then divide by 100 to get the correct value.
The number 100 comes from the power(10, desired precision)
I hope you are on PHP 5.3. I did not enjoy having to do the PHP 5.2 solution very much.
To round up a price in magento you need overwrite a directory/currency model method convert.
Mage_Directory_Model_Currency::convert()
here you will find like this
return $price*$rate
and need to set like this
return round($price*$rate);

How to access to the discount price in Magento?

I'm trying to rewrite a template for the cart.
I need to retrieve the discount amount but I was not able to find where.
Ie If my coupon code gives me $10 discount I want to retrieve 10, if I have a discount of 5% I want to retrieve 5 if the total price is $100.
Thank you.
you can debug your object by printing it out and observing what values it contains
print_r($this->getQuote()->getData());
I used the following code to access discount price. I was accessing the details of last order in a phtml file. For the last order if there was a discount coupon used then I used following code to access the Discount Amount.
$lastOrderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order=Mage::getModel('sales/order')->loadByIncrementID($lastOrderId);
if($lastOrderId) //If order was placed then only display coupon code
{
$coupon=$order->getCouponCode();
echo "<b>Discount coupon used during order:</b>".$coupon;
$disAmount=$order->getDiscountAmount();
echo "<br/>Discount Amount: ".$disAmount;
}

Resources