News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Get shipping cost for product on after product save from admin side

Started by vijayk@splendornet.com, March 16, 2022, 07:14:30 AM

Previous topic - Next topic

vijayk@splendornet.com

We wanted to get the shipping cost of the product when we save the product from the admin side. i.e plgVmAfterStoreProduct (i.e our custom plugin)
Find out matching shipping methods and shipping costs against each shipping method. Can we create a dummy cart using admin user and get shipping cost using cart object.
We are using following shipment plugins
1. weight_countries
2. rules_shipping_advanced

Any help is appreciated. Thank you in advance.

Jumbo!

Here are some example codes. Modify it as per your need.

<?php
JLoader
::register('VirtueMartCart'JPATH_SITE '/components/com_virtuemart/helpers/cart.php');
JLoader::register('vmPSPlugin'JPATH_ADMINISTRATOR '/components/com_virtuemart/plugins/vmpsplugin.php');

$oCart VirtueMartCart::getCart();
$cart  = clone($oCart);

// Reset all cart items.
$cart->cartProductsData = array();

// The virtueart_product_id. Set your desired product ID.
$product_id 1

$cart->cartProductsData[] = array(
'virtuemart_product_id' => (int) $product_id,
'quantity'              => 1,
'customProductData'     => array()
);

// Flag product added
$cart->_productAdded true;

$cart->prepareCartData();

JPluginHelper::importPlugin('vmshipment');

$shipments        = array();
$selectedShipment 0;

JFactory::getApplication()->triggerEvent('plgVmDisplayListFEShipment', array($cart$selectedShipment, &$shipments));

// Print the list of shipment methods.
var_dump($shipments);
?>

vijayk@splendornet.com