I was wondering, has anyone ever created a discount system with PHP for ecommerce? i.e: Before discount the price is $100, after the discount the price becomes $85, and the $100 was stroked.
For changing text to be crossed out, use the <STRIKE> tag (Like this). The rest just involves multiplying current price by 1.00 - discount/100.0, or subtracting current_price * discount/100.0.
You can also use css (text-decoration:line-through;). Css is probably a better choice, really.
For example, a 15% discount means taking the price and multiplying by (1-15/100), which means price * 0.85.
It's quite a short description, but I think you can create a table in your DB with associated to the item ID the discount percentage you want to apply...
Than on the aplication side you can fetch from the DB the original price, print it and after this the new price calculated easily by the original price and the discount percentage.
It's very easy :)
Related
I need to find a way to create Negative product prices in Magento.
We use Magento both as Online shop and POS and in POS we sometimes need
to give a certain discount that simply can't be accomplished with coupons or shopping cart rules.
I did some googling but nothing turned out. Does anybody know how I could create this?
Example:
1 x Apple iPhone 6 - € 699,99
1 x Discount with subscription from provider X - € -100
Total : € 599,99
Thanks in advance!
Why can't you use coupons?
Another possible way to go with is a configureable product option. You need to setup this for each product, however. An option can have a negative price, in your case -100€. You can include an description as text on invoices, but it won't show you "599.99-100.00 = 499.99" but just "499.99" as row total price.
i am working on a plugin for prestashop, i am done with it, but i have stumbled on to an issue.
The program flow is as follows:
A person places an order at the eCommerce website, the order is accepted, the order details such as items, prices, taxes, discounts etc is send to an external invoice API service.
An example of an order could be:
(These prices include taxes)
1x T-shirt 20.64
1x Shipping 125
1x Discount -18.58
(In this particular test case, the discount is 90% off the product, the math is simple 20.64 * 0.90 = 18.58)
Order total after tax is applied: 127.06
This is all fine, but, when i send the details off to the API, the order is saved as the following:
(These prices are saved without tax applied, the tax rate being 25%)
1x T-shirt 16.51
1x Shipping 100
1x Discount -14
Order total after tax is applied: 128.14
As you see, the order totals do not mach, the difference is 1.08, i am thinking this a discount & tax issue.
Its worth noting that the external site does its own math on the values sent, e.g products, tax etc. I cannot influence the way the external invoicing site does its calculations. I think the issue occurs in the order of which the operations are performed on the different platforms.
Its also worth mentioning that the code works perfectly fine when there is no discount present.
What can i do prior to sending the values, so that i get the prestashop price at the external service?
Let the value of the items be v_1 (t-shirt), v_2 (shipping) untaxed values, respectively.
Case 1.
1.25*v_1+1.25*v_2-0.9*1.25*v_1 = 127.06
Case 2 (tax at end)
(v_1+v_2-0.9*v_1)*1.25 = Same as Case 1 after expanding the brackets.
The figure which is amiss is, as you suggest, the -14 discount, which is more like -0.9*16.51=-14.86.
1.08 difference
There is a difference of 86 cents/pence, whatever, between the untaxed discount values. After taxes this difference grows to, 0.86*1.25=1.08, which explains the discrepancy.
To fix the code, the discount calculation needs to be fixed, unless there are other tax considerations that apply to discounts, etc. In other words why is -14 being used, rather than -14.86?
To you second point about the order of events, this should not impact anything - unless discounts are taxed differently.
Fix
Either
The discount calculation is wrong (i.e. 14 should be 14.86), or
The discount value of 14 is correct, in which case a different (tax/discount) methodology than what is being assumed and this needs to be ascertained before you can make a fix for it.
getBaseCalculationPrice (line 315)
Get calculation price used for quote calculation in base currency.
getBaseOriginalPrice (line 389)
Get Original item price (got from product) in base website currency.
getCalculationPrice (line 296)
Get item price used for quote calculation process.
getConvertedPrice (line 434)
Get item price converted to quote currency
getOriginalPrice (line 363)
Get original price (retrieved from product) for item.
getPrice (line 412)
Get item price. Item price currency is website base currency.
I am trying to get the final price that is displayed in the shopping cart, the price that is already been discounted if there are any promotions. Should I use getPrice or getCalculationPrice or getBaseCalculationPrice or any other?
What are differences of all these different get price functions in Magento.
Complicated isn't it? But it has to be complicated so that Magento can cover every possible way to calculate and display a price.
The quick answer is: getCalculationPrice()
I recommend studying the .phtml files that display the prices in the cart because in your question you write 'I am trying to get the final price that is displayed in the shopping cart' and to do that you need to follow the logic through those .phtml files. You need to apply tax logic, tax display logic, currency conversion and display formatting. Set aside a couple of day's time for code reading and testing.
There are a number of price calculations (these do not map one-to-one to the functions you listed above, this just sets the scene). The price might be displayed as:
//price excluding discount without tax in default currency
//price excluding discount without tax in local currency
//price excluding discount with tax in default currency
//price excluding discount with tax in local currency
//price including discount without tax in default currency
//price including discount without tax in local currency
//price including discount with tax in default currency
//price including discount with tax in local currency
Tax is complicated because Magento has WEEE tax and sales tax (WEEE might not apply in your store but the WEEE logic messes up the .phtml files discussed below). AND in your store you might choose to display the price in your cart with or without tax already included. AND the original product price might have been entered including tax.
So Magento is jumping through hoops to, for example, take the price of the product that includes tax in a default currency, subtract the tax, apply discounts, add the local tax for the current locale and convert to the currency of the current locale.
The functions you list are sort-of as you describe them above but think really hard about the different ways a price can be stored and changed and you need to read the code and apply the logic of each situation: a product might have a custom price for example. Most of the function do return the same number or one of two numbers (original price or discounted price)
getBaseCalculationPrice() : includes discounts, no currency conversion, may or may not include tax. Is the same as calling getPrice() if there is no custom price
getBaseOriginalPrice() : excludes discounts, no currency conversion, may or may not include tax
getCalculationPrice() is the same as getConvertedPrice() if there is no custom price
getConvertedPrice() returns the result of getPrice() with a currency conversion applied
getPrice() : includes discounts (I think), no currency conversion, may or may not include tax
getOriginalPrice() : currency conversion of getBaseOriginalPrice()
Which probably doesn't help. You have to read the code.
If you want to to get the price that is displayed in the shopping cart, you should look to follow the logic in those .phtml files that make up the cart layout.
For non-bundled products, see
app/design/frontend/themename/default/template/checkout/cart/item/default.phtml
For bundled products, see
app/design/frontend/themename/default/template/bundle/catalog/product/price.phtml
And note for bundles the function $_priceModel->getTotalPrices() to add to your large collection of pricing functions (it returns the maximum and minimum prices of the bundle (including or excluding tax), so isn't used in the cart display).
So there is a lot of code reading to do. But if you read through all the functions (starting from the .phtml files, not the abstract class - it is easier to work up than try to track down from the abstract class) then you will know what each function does. If you read the functions and set up some test code to output all the different values you will get to the bottom of it.
The tax helper, $_taxHelper = Mage::helper('tax'); also has a function $_taxHelper->getPrice();
In the shopping cart are the cart totals displayed, not the prices.
So i think you should use the following methods if Mage_Sales_Model_Quote_Item:
getRowTotal()
getRowTotalInclTax()
getRowTotalWithDiscount()
Hi i’m developing a eCommerce site in Magento for jewellery business and its based on a “weight”, not the price because gold rate is changing in day by day or more then 3 times in a day.So it is not possible to change the product price every time according to gold rate. Then, how to manage the prices on this scenario?
Example case: Today I have added a 18K gold ring of 10gm to my site and right now gold rate is Rs30,000 per 10gm, so today price of this ring is Rs30,000 but, Next day the rate will be changed (Rs32,000 per 10gm) then, my product price must be changed from Rs30,000 to Rs32,000.
This is not possible to update the price of all products every time.
I am using Magento platform. Please, Share your idea regarding this situation.
To make this simple, you should work on a 2 ways solutions.
In the frontend, do not show price ($_product->getPrice()) but just show the real price according to weight.
Example if you have price/grm stored in the backend use $product->getWeight * Mage::getStoreConfig('mycompany/gold/dayprice').
That way price will be shown dynamically in the product page or list page.
Now you should use an Observer on the add to cart event to change the price to the good one.
This way, don't matter what price is set on the product because showing and adding will use the formulae.
I have a question on what the best way to calculate and store sales tax in the US should be. I am creating an invoice program that can have multiple line items. Here is an example of the issue I'm am running into.
One of my invoice line items looks like this.
quantity 2
amount 1133.67
tax rate 7.5% (.075)
If I add 1133.67 to 1133.67 and multiply by .075, the tax is 170.05.
However, if I take each quantity 1133.67 and apply tax to it individually first, the amount of tax totals up to 170.06.
Obviously, when I'm dealing with taxing each individual quantity, each quantity is being rounded up. But when I total each quantity and then tax the total, there is no rounding up.
I can probably solve this problem by simply editting my table field to allow for 3 decimal places instead of 2.
This may be a question only I can answer, but does it make sense to store tax amounts for each line item or no? I was thinking the data could be useful in reports later down the road.
Wondering what others are doing.
Thanks in advance.
Having worked at a successful sales tax startup, I can tell you "it depends". Local laws vary on whether you calculate sales tax at the line item or invoice level. For some discussion on the topic see:
https://money.stackexchange.com/questions/15051/sales-tax-rounded-then-totaled-or-totaled-then-rounded
I can also tell you that US sales tax is extremely complicated. There are over 10,000 jurisdictions that can levy a tax (state, county, city, and special districts such as stadium districts, metropolitan transport districts, water districts, etc.). The boundaries of those districts are not well defined an a readily available public source, and certainly do not conform to ZIP code boundaries.
If you want to get it right, your best bet is to use a sales tax calculation service. There are several SAAS solutions that are well-suited for web apps.