I'm having issue with calculation of price without tax, when I put price without discount it counts okay, because I made some changes in presta core, for example if I put product with price of 4,5 tax incl and 8% tax I get price - 4,17 tax excl, and that is correct.
(4,5*100)/108 = 4,16666 rounds up.
After giving specific price -15% I get price tax incl 3,83 which is correct, but I get 3,54 price tax excl which is incorrect (correct should be 3,55), I assume that everything counts using price tax excl instead of incl and counts like this
4,17 - (4,17*0,15) = 3,5445 (which php rounds to 3,54 instead of 3,55),
Do you have any idea in which controller or source file should I look to modify PrestaShop behaviour?
Inside "Product" class, check the static method getPriceStatic that is basically handling everything related to retrieving a product price.
You'll end to explore Product::priceCalculation and many methods on the SpecificPrice class that are related to calculation of discounts.
Related
I'm trying to take account of the package weight in the total weight of the cart so I can bill the right shipping cost.
I tried adding a filter on 'woocommerce_cart_contents_weight' like explained there
So I added the following code snippet
function add_package_weight_to_cart_contents_weight( $weight ) {
$weight = $weight * 1.3; // add 30%
return $weight;
}
add_filter('woocommerce_cart_contents_weight', 'add_package_weight_to_cart_contents_weight');
I've also added a snippet to print cart weight on cart page, and I can see that the weight filter isn't applied : The total weight of the cart doesn't change wether the snippet is active or not.
I also tried putting exactly 900g articles in the cart so that, with the box weight, it goes over 1kg and change price, but the shipping price is still the one for under 1kg.
Any idea on why it isn't applied and how I could fix it ?
Your code works and only affects WC_Cart method get_cart_contents_weight() usage.
Now for shipping methods, as cart items can be divided into packages, the weight is calculated for each shipping package and doesn't use WC_Cart method get_cart_contents_weight(). Instead it will make a calculation on the cart items for each package.
A possible way should be to use the filter hook woocommerce_package_rates to alter cost based on the package weight calculation. But this is going to be much more complicated as it seems that you are using 3rd party plugins.
I'm working with magento 1.9.3 and need to change the shipping costs calculation based on table rate to use weight and category vs destination in the same table rate.
I have some products need to add extra cost based on category vs destination and the rest of products use the normal weight vs destination shipping cost calculation.
Before start coding i would like to have a different approach to find an easy and clean solution to this.
By now this is the idea
Add a new condition_name to the CSV named package_weight_category with category id as condition value
Modify the getRate method to find in the DDBB using the categories of the products in the cart and condition_name = 'package_weight_category'
If anything is found save the cost
Subtract the weight of the products of the categories found to the total weight
If weight >0 find the cost of the updated weight and add it to the cost
Return the calculated cost
My questions are
Is this solution functional?
It's possible pass the info of the categories and quantity of the products to the Mage_Shipping_Model_Rate_Request object?
Any better solution or different approach to solve this?
Thanks in advance just for reading
I am having a problem with the following:
I use "TM extra product options" to add some extra options when buying a product. For example:
Box of chocolate (€40,00)
Extra decorations (extra option) (€15,00)
I offer free shipping on orders above €50,00. The problem is, that the extra fees are calculated AFTER the subtotal, and the shipping is calculated based on this subtotal. In the example above, you still have to pay for the shipping, which i don't want to.
How can I make sure the fee is calculated inside the subtotal (but still mentioned as seperated product) of have the shipping calculated based on the subtotal+fees?
Thanks in advance!
PS:
Something along this way:
$woocommerce_subtotal = $woocommerce_subtotal + $woocommerce_product_fee;
// set fee on 0 after this line
$woocommerce_product_fee = 0;
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.
For a customer I am building a Virtuemart 2.0.26d website.
Because of a local law, for each unit of a product that is ordered a fee must be added.
So, when ordering 4 products, the fee must be charged 4 times. By law it is required that the total sum of this fee is visible on the invoice/order confirmation.
I looked at the price rules in Virtuemart, but they don't seem to have an option for this. There is a price modifier after tax, but then the fee is visibile as an negative discount. Something I don't want.
The only solution I came up with is to make a new product for the fee and programmatically add this product for each unit. Can this be done by making a Virtuemart Plugin, or must I change the core for this?
Or are there better solutions for this problem?
You can add extra charge by Taxes & Calculation Rules.
create new rules and select tax per product for Type of Arithmetic Operation and select Math Operation + Or +% as per you want to add extra fee per product.
You could add a custom field to each product with the fee amount and alter the code of the payment plugin to add this fee to your order.