Add min_stock_amount and best_before_days to KrogerConverter

This commit is contained in:
Zeb Fross 2020-04-01 19:32:53 -07:00
parent 5d980a9bd7
commit 53f1321e19
3 changed files with 71 additions and 6 deletions

View File

@ -38,11 +38,17 @@ class KrogerToGrocyConverter
$barcode = KrogerToGrocyConverter::ConvertUpcToBarcode($item["baseUpc"]); $barcode = KrogerToGrocyConverter::ConvertUpcToBarcode($item["baseUpc"]);
$min_stock_amount = 1;
$quantity = $item['quantity']; $quantity = $item['quantity'];
if ($item['weighted'] && array_key_exists('averageWeight', $item['detail'])) if ($item['weighted'] && array_key_exists('averageWeight', $item['detail']))
{ {
$quantity = round($item['quantity'] / $item['detail']['averageWeight']); $quantity = round($item['quantity'] / $item['detail']['averageWeight']);
} }
else if ($item['weighted'])
{
// this is semi-arbitrary; some things are bought by weight but with no way to determine quantity
$min_stock_amount = $item['quantity'] / 4;
}
$quantity_units = $default_quantity_units; $quantity_units = $default_quantity_units;
if (array_key_exists('unitOfMeasure', $item)) if (array_key_exists('unitOfMeasure', $item))
@ -57,8 +63,8 @@ class KrogerToGrocyConverter
} }
} }
$best_before_days = 21;
$location = $default_location_id; $location = $default_location_id;
if (array_key_exists('categories', $item['detail']) && count($item['detail']['categories']) > 0) if (array_key_exists('categories', $item['detail']) && count($item['detail']['categories']) > 0)
{ {
$category = $item['detail']['categories'][0]['categoryCode']; $category = $item['detail']['categories'][0]['categoryCode'];
@ -67,30 +73,36 @@ class KrogerToGrocyConverter
case 1 /*adult beverage*/: case 1 /*adult beverage*/:
$location = 3 /*pantry*/; $location = 3 /*pantry*/;
$quantity_units = 10 /*bottle*/; $quantity_units = 10 /*bottle*/;
$best_before_days = -1;
break; break;
case 6 /*bakery*/:
case 7 /*baking goods*/: case 7 /*baking goods*/:
case 10 /*breakfast*/: case 10 /*breakfast*/:
case 12 /*canned and packaged*/: case 12 /*canned and packaged*/:
case 13 /*cleaning products*/: case 13 /*cleaning products*/:
case 33 /*pasta, sauces, & grain*/: case 33 /*pasta, sauces, & grain*/:
case 36 /*produce*/:
case 73 /*natural & organic*/: case 73 /*natural & organic*/:
case 75 /*personal care*/: case 75 /*personal care*/:
case 76 /*health*/: case 76 /*health*/:
$location = 3 /*pantry*/;
$best_before_days = -1;
break;
case 36 /*produce*/:
case 6 /*bakery*/:
$location = 3 /*pantry*/; $location = 3 /*pantry*/;
break; break;
case 15 /*dairy*/: case 15 /*dairy*/:
case 16 /*deli*/: case 16 /*deli*/:
case 28 /*meet & seafood*/: case 28 /*meat & seafood*/:
$location = 2 /*fridge*/; $location = 2 /*fridge*/;
break; break;
case 20 /*frozen*/: case 20 /*frozen*/:
$location = 6 /*freezer*/; $location = 6 /*freezer*/;
$best_before_days = -1;
break; break;
case 37 /*snacks*/: case 37 /*snacks*/:
case 77 /*candy*/: case 77 /*candy*/:
$location = 4 /*candy cupboard*/; $location = 4 /*candy cupboard*/;
$best_before_days = 360;
break; break;
} }
} }
@ -102,16 +114,18 @@ class KrogerToGrocyConverter
'qu_id_stock' => $quantity_units, 'qu_id_stock' => $quantity_units,
'qu_factor_purchase_to_stock' => 1, 'qu_factor_purchase_to_stock' => 1,
'barcode' => $barcode, 'barcode' => $barcode,
'default_best_before_days' => 21, 'default_best_before_days' => $best_before_days,
'quantity' => $quantity, 'quantity' => $quantity,
'min_stock_amount' => $min_stock_amount,
'transaction_date' => $transactionDate, 'transaction_date' => $transactionDate,
'price_paid' => $item['pricePaid'], 'price_paid' => $item['pricePaid'] / $item['quantity'],
'picture_url' => (array_key_exists("mainImage", $item['detail']) ? $item['detail']['mainImage'] : null) 'picture_url' => (array_key_exists("mainImage", $item['detail']) ? $item['detail']['mainImage'] : null)
); );
array_push($products, $product); array_push($products, $product);
} }
} }
return $products; return $products;
} }

View File

@ -110,6 +110,45 @@
"pharmacy": false, "pharmacy": false,
"managerOverride": false, "managerOverride": false,
"weighted": false "weighted": false
},
{
"itemIdentifier": "0000000004648",
"baseUpc": "0000000004648",
"department": "57",
"unitOfMeasure": "LBR",
"detail": {
"upc": "0000000004648",
"customerFacingSize": "1 lb",
"description": "Mushrooms - Crimini - Bulk",
"familyTreeCommodityCode": "613",
"familyTreeDepartmentCode": "57",
"familyTreeSubCommodityCode": "8067",
"mainImage": "https://www.kroger.com/product/images/small/front/0000000004648",
"soldInStore": true,
"categories": [{
"category": "Produce",
"categoryCode": "36"
}
]
},
"quantity": 0.84,
"totalSavings": 0,
"extendedPrice": 3.35,
"pricePaid": 3.35,
"priceModifiers": [],
"unitPrice": 3.99,
"itemType": "NORMAL",
"entryMethod": "KEYED_ITEM_CODE",
"imageUrl": "https://www.kroger.com/product/images/small/front/0000000004648",
"detailUrl": "/p/item/0000000004648",
"sellableUpc": "0000000004648",
"containerDeposit": false,
"managerOverride": false,
"weighted": true,
"giftCard": false,
"pharmacy": false,
"fuel": false,
"managerOverrideIgnored": false
} }
], ],
"transactionTime": "2020-03-21T09:14:00" "transactionTime": "2020-03-21T09:14:00"

View File

@ -14,5 +14,17 @@
"barcode": "0072220005165", "barcode": "0072220005165",
"quantity": 3, "quantity": 3,
"transaction_date": "2020-03-21" "transaction_date": "2020-03-21"
}, {
"name": "Mushrooms - Crimini - Bulk",
"location_id": 3,
"qu_id_purchase": 2,
"qu_id_stock": 2,
"qu_factor_purchase_to_stock": 1,
"barcode": "0000000046480",
"default_best_before_days": 21,
"quantity": 0.84,
"transaction_date": "2020-03-21",
"price_paid": 3.988095238095238,
"picture_url": "https:\/\/www.kroger.com\/product\/images\/small\/front\/0000000004648"
} }
] ]