[TYPO3-commerce] delivery costs based on total costs
Franz Koch
typo.removeformessage at fx-graefix.de
Wed Oct 3 21:17:17 CEST 2007
Hi,
> I am searching for a method in which I can say:
>
> * total costs to 100,- => delivery costs 5,-
> * total costs from 100,- to 300,- => delivery costs 4,-
> * total costs above 300,- => no delivery costs
>
> Does anyone has some experience with this in commerce?
I used a hook for this, using the price-scale fields to define which
delivery price applies for which total cost.
hook 'postAddArticle' or so from the basket.
my function:
------------
// recalculate delivery price
if ($parent->basket_items[$itemId]->getArticleTypeUid() ==
DELIVERYArticleType) {
$basketItem = &$parent->basket_items[$itemId];
$articleObj = &$basketItem->article;
//get correct price based on total purchase costs
$arrayOfPricesUids = $articleObj->getPossiblePriceUids();
if (is_array($arrayOfPricesUids)) {
foreach ($arrayOfPricesUids as $priceUid) {
$prices[$priceUid] = new
tx_commerce_article_price($priceUid,$basketItem->lang_id);
$prices[$priceUid]->load_data();
}
}
if (is_array($prices)) {
$price_id = $articleObj->get_article_price_uid();
$basketPriceNet = $parent->getArticleTypeSumNet(NORMALArticleType);
foreach ($prices as $key => $priceObject) {
if ($priceObject->price_scale_amount_start*100 < $basketPriceNet) {
$basketItem->price_uid = $key;
$basketItem->price = $priceObject;
}
}
$basketItem->priceNet = $basketItem->price->get_price_net();
$basketItem->priceGross = $basketItem->price->get_price_gross();
$basketItem->recalculate_item_sums();
}
}
-----------
maybe that helps. You probably have to loop through the basket items and
call this code snippet inside the loop, because I added a new hook to
commerce (which hopefully will make it into the core) which I used for it.
--
Kind regards,
Franz
More information about the TYPO3-project-commerce
mailing list