[Typo3-shop] Shipping costs related to weight
Christian Buelter
buelter at kennziffer.com
Mon Jul 25 13:39:18 CEST 2005
Franz Holzinger schrieb:
Hi Franz,
thank you for pointing me into the right directions!
>> by accident, i need something similiar right now, so i adapted that
>> function as you proposed.
> great! This was rather easy, wasn't it?
Yes, I was surprised, too... :-)
> This will come in a modified way into the next tt_products version.
Great!
And I added some more stuff:
>
>>
>> I need another thing as well:
>> Do you have an idea, how to calculate the shipping costs depending of
>> from what categories the products come?
>> For example: The shipping costs are calculated from weight, and if at
>> least one product from category xy is in the basket, the shipping
>> costs will be at least 5 €.
>>
>
> The configuration for shipping prices needs again a modification.
>
> plugin.tt_products.shipping {
> 10.priceTax.type = weight
> 10.where = category = 1
> 10.priceTaxWhere = 5
> 10.priceTax.1 = 4
> 10.priceTax.6 = 5.8
> }
>
> So modify the code again to use the where condition to get price1 = 5 if
> the condition is true.
>
> Then calculate the price as before and after that use the highest price
> of both.
>
> Even the PIDs can now be calculated using a where condition.
> see function getPID
I made the changes you proposed, but the configuration differs a bit.
OK, here we go.
I changed the "weight"-configuration as you did it ("type = weight"), it
can now be configured differently for each entry in the
"shipping"-configuration.
Now, this is how to define a minimum shipping cost depending on the
category (PID of the page), a product has:
10.priceTax.WherePIDMinPrice.155 = 7.5
Where 155 is the PID and 7.5 is the minimum price taken for shipping
costs when at least one product in the basket comes from the page with
that PID.
Example:
plugin.tt_products.shipping {
10.title = Parcel
10.priceTax.type = weight
10.priceTax.WherePIDMinPrice.155 = 7.5
10.priceTax.1 = 1.5
10.priceTax.500 = 2.5
10.priceTax.1000 =3.5
}
These are the changes in the tt_products - class:
I need tcemain for getPID, so this class has to be included.
> require_once(PATH_t3lib."class.t3lib_tcemain.php");
Here comes the modified function GetPaymentShippingData, and the new
function getPIDListFromBasket.
> /**
> * returns the List of PIDs of all products in the basket, every page is represented once
> */
> function getPIDListFromBasket() {
> $PIDList='';
> foreach ($this->basketExt as $key=>$data) {
> $pid=t3lib_TCEmain::getPID('tt_products',$key);
> if (!strstr($PIDList,$pid)) {
> if ($PIDList) $PIDList.=',';
> $PIDList.=$pid;
> }
> }
> return $PIDList;
> }
>
> function GetPaymentShippingData(
> &$countItem, &$priceShippingTax,
> &$countTotal) {
> $priceSingleShippingTax = 0;
> // get the priceTax configuration
> $confArr = $this->basketExtra["shipping."]["priceTax."];
> if ($confArr) {
> // count the total amount of products in the basket
> $countTotal = 0;
> foreach ($countItem as $key=>$count2) {
> $countTotal += $count2;
> }
>
> // sort the priceTax configuration in reverse order, so that it goes from highest to lowest
> krsort($confArr);
> reset($confArr);
>
> // get the List of PIDs for the goods stored in the basket
> $PIDList=$this->getPIDListFromBasket();
> // compare PIDList with values set in priceTaxWherePIDMinPrice in the SETUP
> // if they match, get the min. price
> // if more than one entry for priceTaxWherePIDMinPrice exists, the highest is value will be taken into account
> $minPrice=0;
> if ($this->basketExtra['shipping.']['priceTax.']['WherePIDMinPrice.']) {
> foreach ($this->basketExtra['shipping.']['priceTax.']['WherePIDMinPrice.'] as $minPricePID=>$minPriceValue) {
> if (strstr($PIDList,strval($minPricePID)) && $minPrice<doubleval($minPriceValue)) {
> $minPrice=$minPriceValue;
> }
> }
> }
>
> while (list ($k1, $price1) = each ($confArr)) {
> // now decide, if we want to use the AMOUNT of goods or the WEIGHT of goods for calculationg the shipping fee
> // this can be configured in Typoscript SETUP
> // weights have to be configured in GRAMS!
> if ($this->basketExtra["shipping."]["priceTax."]["type"]=='weight') {
> if ($this->calculatedWeight*1000 >= intval($k1)) {
> $priceShippingTax = $price1;
> break;
> }
> } else {
> if ($countTotal >= intval($k1)) {
> $priceShippingTax = $price1;
> break;
> }
> }
> }
> // compare the price to the min. price
> if ($minPrice>$priceShippingTax) $priceShippingTax=$minPrice;
> }
> }
More information about the TYPO3-project-tt-products
mailing list