I'm using magento C.E 1.7. I use all shipping methods of magento and I'm viewing only one shipping method in the front end, which has higher priority. I'm using table rate shipping for some countries.
I wanted to add special fixed shipping price for some products when they shipped to that countries only. So that, I added new shipping method namely 'flat rate per product', by using a new module.
Based on this module, a text box is added to all the products in admin to specify the special shipping price. If I filled this field with some value, It considers it as a special shipping price. And if not filled it, it will be considered as special shipping price is $0.
So I have given least priority in the sort order for this shipping method to avoid this method from viewing on front end when products without special shipping price and products with special shipping price both are added into the cart.
So that, If only the special shipping priced product is added to the cart, It shows only table rate shipping method in front end.
I checked the code in availble.phtml. There is a foreach loop to proceed with available shipping methods. I need to check the availability of the 'flat rate per product' and it's price value for the product before start of loop execution.
I tried to get all the values of the array. But I could not. Can anyone help on this?
you can use this code:
<?php
$methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
$shipMethods = array();
foreach ($methods as $shippigCode=>$shippingModel)
{
$shippingTitle = Mage::getStoreConfig('carriers/'.$shippigCode.'/title');
$shipMethods[$shippigCode] = $shippingTitle;
}
return $shipMethods;
?>
Related
I have Magento 2.3 website, which is connected with third-party sales channels like Amazon, eBay and BOL to sync products and get orders data back into the Magento system and send shipment created by retailer in Magento to those third-party sales channels.
Our system was initially configured to have prices in Magento including VAT. But after EU VAT changes we needed to use Magento prices excluding VAT to properly manage prices on each sales channels and in Magento stores also.
For BOL sales channel, when I receive order, I need to deduct the shipping cost based on item weight and VAT % from the item price we receive from BOL, because BOL item price includes all amounts in item while in Magento we set shipping cost separately.
I am able to set the Custom Price after doing all the calculation required to set final excluded VAT item price in Price column(note, I renamed it to BOL Price) but our Magento system is configured to use Original Price(Magento product price) setup via admin to calculate taxes. In this case, our Original Price is not same as Custom Price we set after our custom calculations. So Product Sub-total and all other prices/calculation does not match the correct values. I know we can configure Magento to use Custom Price for TAX calculation but as we have other sales channel also depending on this setting and developed on Original Price TAX calculation, I need to use same configuration for this. Hence, this requires to set same Custom Price to set as Original Price also to get correct VAT and totals. But not able to get that Original Price updated with any method I could found. Which still uses Magento admin price instead of Price I wanted to set which is same as Price I calculated for Custom Price.
Please check code below, where I tried to update Product price before adding it to cart and also tried cart item product price update after adding it to the cart:
public function addProductToCart(string $quoteId, $item, string $storeCode)
{
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($quoteId, 'masked_id');
/** #var \Magento\Quote\Model\Quote $quote */
$quote = $this->cartRepository->get($quoteIdMask->getData('quote_id'));
$price = $item->unitPrice()->toScalar(); //Item price on BOL
//CALCULATION TO GET FINAL PRICE BEFORE ADDING IT HERE
$product = $this->getProductByEan($item->product()->ean()->toString(), $storeCode); //Get product to add in quote by EAN
// Trying to set Original Price of product before adding product item to quote
$product->setPrice($price));
$product->setOriginalPrice($price);
$product->setBasePrice($price);
$product->setConvertedPrice($price);
$product->setBaseOriginalPrice($price);
$product->setPriceInclTax($price);
$product->setIsSuperMode(true);
$cartItem = $quote->addProduct(
$product,
$item->quantity()->toScalar()
);
$quote->setIsSuperMode(true);
//Update Custom Price [Works]
$cartItem->setOriginalCustomPrice($price);
$cartItem->setCustomPrice($price);
// Trying to set Original Price of cart item product after item added to quote [NOT WORKING]
$cartItem->getProduct()->setPrice($price);
$cartItem->getProduct()->setOriginalPrice($price);
$cartItem->getProduct()->setBasePrice($price);
$cartItem->getProduct()->setConvertedPrice($price);
$cartItem->getProduct()->setBaseOriginalPrice($price);
$cartItem->getProduct()->setPriceInclTax($price);
$cartItem->getProduct()->setIsSuperMode(true);
$this->cartRepository->save($cartItem->getQuote());
}
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 trying to get the shipping method or cost of shipping for a WooCommerce order - I'm writing a custom email template that is different depending on free delivery vs paid delivery.
I found a function called get_total_shipping(), but this is now deprecated and I cannot find a replacement - does one exist?
I've noticed that the shipping amount is stored in a hidden meta field (_order_shipping), which I can access, but I worry that this might break on future WooCommerce updates.
Since Woocommerce 3 get_total_shipping() method is replaced by get_shipping_total() .
So there is actually 2 available CRUD getters methods for shipping totals in WC_Abstract_Order Class that can be used on the WC_Order instance object:
get_shipping_total() that is the shipping total excluding taxes
get_shipping_tax() that is the shipping taxes total
So you will use them with the $order variable object simply this way:
$shipping_total = $order->get_shipping_total();
$shipping_tax = $order->get_shipping_tax();
There is also get_shipping_to_display() method that will output the formatted shipping total.
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;
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/