Skip to content

Commit

Permalink
fix bug in conjunction with isotope
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyborn committed Aug 11, 2022
1 parent 57ec3cf commit 9018919
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/Resources/contao/classes/OpenGraphIsotope.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,34 @@ public static function addModuleData( $objModule ): void {
// add shipping weight
if( isset($objProduct->shipping_weight) ) {

$weightProduct = null;
$weightProduct = Weight::createFromTimePeriod($objProduct->shipping_weight);
$weightMin = new Weight(1000,'g');

$objScale = new Scale();
$objScale->add($weightProduct);
if( $weightProduct ) {

// convert small weights to gram (g)
if( $objScale->isLessThan($weightMin) ) {
$weightMin = new Weight(1000,'g');

$convertedUnit = 'g';
$convertedWeight = Unit::convert($weightProduct->getWeightValue(), $weightProduct->getWeightUnit(), 'g');
$objScale = new Scale();
$objScale->add($weightProduct);

// convert larger weights to kilogram (kg)
} else {
// convert small weights to gram (g)
if( $objScale->isLessThan($weightMin) ) {

$convertedUnit = 'kg';
$convertedWeight = Unit::convert($weightProduct->getWeightValue(), $weightProduct->getWeightUnit(), 'kg');
}
$convertedUnit = 'g';
$convertedWeight = Unit::convert($weightProduct->getWeightValue(), $weightProduct->getWeightUnit(), 'g');

// convert larger weights to kilogram (kg)
} else {

$convertedWeight = number_format($convertedWeight, 2, '.', '');
$convertedUnit = 'kg';
$convertedWeight = Unit::convert($weightProduct->getWeightValue(), $weightProduct->getWeightUnit(), 'kg');
}

OpenGraph3::addProperty('og_product_shipping_weight_value',$convertedWeight,$objProduct);
OpenGraph3::addProperty('og_product_shipping_weight_unit',$convertedUnit,$objProduct);
$convertedWeight = number_format($convertedWeight, 2, '.', '');

OpenGraph3::addProperty('og_product_shipping_weight_value',$convertedWeight,$objProduct);
OpenGraph3::addProperty('og_product_shipping_weight_unit',$convertedUnit,$objProduct);
}
}

OpenGraph3::addProperty('og_product_product_link',Environment::get('url') . Environment::get('requestUri'),$objProduct);
Expand Down

0 comments on commit 9018919

Please sign in to comment.