Skip to content

Commit

Permalink
Merge branch 'release/4.0.6' into v4
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Feb 22, 2023
2 parents 6ddf807 + 9024d45 commit edb7763
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Recipe Changelog

## 4.0.6 - 2023.02.22
### Fixed
* Fix API Requests ([#65](https://github.com/nystudio107/craft-recipe/pull/65))

## 4.0.5 - 2023.02.21
### Changed
* Refactored the docs buildchain to use a dynamic docker container setup
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-recipe",
"description": "A comprehensive recipe FieldType for Craft CMS that includes metric/imperial conversion, portion calculation, and JSON-LD microdata support",
"type": "craft-plugin",
"version": "4.0.5",
"version": "4.0.6",
"keywords": [
"craft",
"cms",
Expand Down
4 changes: 2 additions & 2 deletions src/assetbundles/recipefield/dist/js/Recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
ingredients.push(ingredient.join(' '));
});

var serves = $('#fields-' + field + 'serves').val();
var serves = $('#' + field + 'serves').val();

$('.fetch-nutritional-info button').addClass('disabled');
$('.fetch-nutritional-info .spinner').removeClass('hidden');
Expand All @@ -82,7 +82,7 @@
Craft.cp.displayError(response.error);
} else {
$.each(response, function (index, value) {
$('#fields-' + field + index).val(value);
$('#' + field + index).val(value);
});
}

Expand Down
24 changes: 12 additions & 12 deletions src/services/NutritionApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ public function getNutritionalInfo(array $ingredients, int $serves = null): arra
$yield = $result->yield ?: 1;

return [
'servingSize' => round($result->totalWeight / $yield, 0) . ' grams',
'calories' => round($result->totalNutrients->ENERC_KCAL->quantity / $yield, 0),
'carbohydrateContent' => round($result->totalNutrients->CHOCDF->quantity / $yield, 1),
'cholesterolContent' => round($result->totalNutrients->CHOLE->quantity / $yield, 1),
'fatContent' => round($result->totalNutrients->FAT->quantity / $yield, 1),
'fiberContent' => round($result->totalNutrients->FIBTG->quantity / $yield, 1),
'proteinContent' => round($result->totalNutrients->PROCNT->quantity / $yield, 1),
'saturatedFatContent' => round($result->totalNutrients->FASAT->quantity / $yield, 1),
'sodiumContent' => round($result->totalNutrients->NA->quantity / $yield, 1),
'sugarContent' => round($result->totalNutrients->SUGAR->quantity / $yield, 1),
'transFatContent' => round($result->totalNutrients->FATRN->quantity / $yield, 1),
'unsaturatedFatContent' => round(($result->totalNutrients->FAMS->quantity + $result->totalNutrients->FAPU->quantity) / $yield, 1),
'servingSize' => round($result->totalWeight ?? 0 / $yield, 0) . ' grams',
'calories' => round($result->totalNutrients->ENERC_KCAL->quantity ?? 0 / $yield, 0),
'carbohydrateContent' => round($result->totalNutrients->CHOCDF->quantity ?? 0 / $yield, 1),
'cholesterolContent' => round($result->totalNutrients->CHOLE->quantity ?? 0 / $yield, 1),
'fatContent' => round($result->totalNutrients->FAT->quantity ?? 0 / $yield, 1),
'fiberContent' => round($result->totalNutrients->FIBTG->quantity ?? 0 / $yield, 1),
'proteinContent' => round($result->totalNutrients->PROCNT->quantity ?? 0 / $yield, 1),
'saturatedFatContent' => round($result->totalNutrients->FASAT->quantity ?? 0 / $yield, 1),
'sodiumContent' => round($result->totalNutrients->NA->quantity ?? 0 / $yield, 1),
'sugarContent' => round($result->totalNutrients->SUGAR->quantity ?? 0 / $yield, 1),
'transFatContent' => round($result->totalNutrients->FATRN->quantity ?? 0 / $yield, 1),
'unsaturatedFatContent' => round(($result->totalNutrients->FAMS->quantity ?? 0 + $result->totalNutrients->FAPU->quantity ?? 0) / $yield, 1),
];
} catch (Exception $exception) {
$message = 'Error fetching nutritional information from API. ';
Expand Down

0 comments on commit edb7763

Please sign in to comment.