Dynamic Prices for a product which changes every hour - php

I am running a silver bullion website. The price of silver changes every hour. The silver price is stored in a variable. I am searching for a shopping cart for wordpress that can do the following things:
For example I have a product name Silver Coin:
Silver Selling price at the present hour is $25.5
---> The cart Should pick this value from a PHP variable But dont output it as actual price of the product
The product price will be 1.2% of $25.5 ---------------->
This Should be the actual price of product and output as the product price
How to get this functionality and with which shopping cart? I am using WP-eCommerce Plugin, anyone can help please.

I did something similar not long ago and it was fairly straight forward.
Create a function in your themes function.php file which returns the latest price of silver. If you only want to pull it in every hour then this function could check a time stamp of when it was last retrieved and then either return the price from the database or retrieve the new price and update the database.
WP-eCommerce supports templates, find the correct template file which displays your products and inside the loop where the price is being displayed replace their function call with your own. I think the function is called, wpsc_the_product_price()
If for example some of your prices are 1.5% of the silver price and others are 1.2% then you could set the percentage in the product price. Then instead of replacing the function call in the template file use it to retrieve the product percentage and along with your silver price calculate the product price.

Related

Calculate, display and add price based on weight n wordpress

I am designing a grocery website in wordpress where in I wish to display price per kg for vegetable and user will now enter the weight they wish and price should get recalculated and displayed and added to cart(after user click on add to cart button).
I have tried few plugins like Price per product and Price Measurement but nothing seems to work. How can this be achieved?
Just multiply the price per Kg by the weight requested to get the price.

Want to add a checkbox to product page on woocommerce/measurement calculator plugin

I want to add a checkbox to products in certain categories in my online shop, but when the checkbox is ticked it will need to add 'x' amount to the total of the product.
To complicate things further, the product is total is calculated by (area x product price) after the user has inputted their required Length and Width, the checkbox will need to use the area value and then multiply the area by 2.5 and then add that sub-total to the grand total of the product. It's an add-on to the product. If you catch my drift?
Here's a link to a sample product page. The products are carpets, so when you to tick the checkbox, the carpets will have a stain protection applied and will be charged for.
Is there any snippet of code that could help me here?
So it was a relatively easy solution. It was just a case of turning the product into a variable product and using attributes to make a "yes or no" drop-down box, with one of the options having an increased price. This makes the price change before the area is calculated, unlike the 'product add-ons' plugin, which adds on after.
I can't believe it took me two weeks to find the answer to this.

How to set custom price for a product in Magento for only the first of that product added to the cart?

I trying to allow users to get the first product sample they add to their cart for free, but any samples they add after (including the one they already added) should be normal price. Right now I using setOriginalCustomPrice in a module, but the customer can change the quantity, and the price stays at zero instead of going up. Anyone know how to go about this?
You can achieve this by a simple calculation where you are using setOriginalCustomPrice.Currently I think you are setting price 0.Instead of doing this,use following logic to set custom price.
$customPrice=$qtyincart*$productPrice-$productPrice.
So if user add 1 qty then $customPrice will be 0 else will equal to sum of qty-1.
I hope this solve your purpose.

magento customize quote collectTotals to show the updated totals

hey i'm implementing a custom discount system since magento discount system does not feet my requirements so i'm trying to apply a discount on an Mage_Sales_Model_Quote_Item I've read some and I've found the following function setOriginalCustomPrice the thing is that it applies on the item, and if the user changes the quantity he will get the discount on the item with the new quantity, so i'm trying to use a different method addOption on the item and only on the cart page show the calculations based on the quantity in the option value
$item->addOption(array('code'=>'promo','value' => serialize(['amount'=>10,'qty'=>1])));
and in the cart page
$promo = $item->getOptionByCode('promo');
echo '<div class="orig-price">'.$item->getOriginalPrice().'</div>';
echo '<div class="new-price">'.$item->getOriginalPrice() - ($promo['amount'] * $promo['qty']).'</div>';
the problem is that it does'nt actually apply the new price on the product,
so i want to customize Mage_Sales_Model_Quote->collectTotals() to show my discounts
and send it to the admin back-end when order is completed
how can i achieve that?
thanks in advance
I think there is a fundamental flaw in your approach. I'm not sure what you don't like in standard discounts, and what you can't achieve with catalog or shopping cart rules, but what you're trying to do definitely breaks these features (along with my heart).
However, if you're sure about what you're trying to do, then don't customize Mage_Sales_Model_Quote->collectTotals().
This function just... well, it collects all totals: subtotal, shipping, discount, etc. And it looks like you're changing only price output, but Magento itself doesn't know anything about it.
So if you want to let Magento know that you're changing the item price, you have to either add your own total, or change one of the existing totals. After that Magento will do everything else. Since after your changes Magento outputs already calculated price instead of original one, it may be strange for customer to see the original price in the cart and the additional discount total. So it looks like you will have to change subtotal total.
To do that you have to rewrite Mage_Sales_Model_Quote_Address_Total_Subtotal class in your extension and insert your calculation in _initItem() method. Around line 111 in the original file you will see the code:
$item->setPrice($finalPrice)
->setBaseOriginalPrice($finalPrice);
And this is where Magento sets price for the item, so you can insert your calculations and change $finalPrice before that. If you have virtual products, you will have to change collect() method too.

How to use a special formula in Magento cart

Please suppose:
Row product price = $1.5;
Quantity = 3;
Instead of total amount $4.5, it should be different amount based on finished product criteria.
Using configurable product options/attributes, my product page can display its finished product price correctly based on a special formula (written in JS).
Though I can calculate correctly using JS function (formula) on product page, I can't display its calculated amount on shopping cart page. How can I pass the calculated amount to shopping cart page so that its calculation persists in rest of steps in checkout?
You need an observer when adding products to cart, based on the same logic (options and quantity) as your JS function.
You have to build an observer that catches the add-to-cart event sales_quote_add_item and put your logic there. You can define the product price with
$observer->getEvent()->getQuoteItem()->setOriginalCustomPrice([your price])
This price will be saved to the quote object and persists in other steps in checkout.
If you want to calc the row total separate from price per item, you have to overwrite the calcRowTotal() method from the Mage_Sales_Model_Quote_Item class like explained here:
http://www.magentocommerce.com/boards/viewthread/220715/

Categories