@@ -332,7 +332,8 @@ func (i orderManager) GetPriceIdList(packageKeyname string, itemKeynames []strin
332332 return nil , err
333333 }
334334 var prices []int
335- categoryDict := map [string ]int {"gpu0" : - 1 , "pcie_slot0" : - 1 }
335+ // start at -1 so we can increment before we use it. 0 is a valid value here
336+ categoryDict := map [string ]int {"gpu0" : - 1 , "pcie_slot0" : - 1 , "disk_controller" : - 1 }
336337
337338 for _ , itemKeyname := range itemKeynames {
338339 var newItems []datatypes.Product_Item
@@ -355,10 +356,10 @@ func (i orderManager) GetPriceIdList(packageKeyname string, itemKeynames []strin
355356 itemCategory = * matchingItem .ItemCategory .CategoryCode
356357 }
357358
359+ // Normal items
358360 if _ , ok := categoryDict [itemCategory ]; ! ok {
359361 for _ , p := range matchingItem .Prices {
360- if ((p .LocationGroupId != nil && * p .LocationGroupId == 0 ) ||
361- p .LocationGroupId == nil ) && p .Id != nil {
362+ if isDefaultPrice (p ) {
362363
363364 capacityMin := - 1
364365 capacityMax := - 1
@@ -386,19 +387,23 @@ func (i orderManager) GetPriceIdList(packageKeyname string, itemKeynames []strin
386387 }
387388 }
388389 }
390+ // Items in categoryDict need special handling if there are more than 1
389391 } else {
390- var PriceIdList [] int
392+
391393 categoryDict [itemCategory ] += 1
392- categoryCode := itemCategory [: len ( itemCategory ) - 1 ] + strconv . Itoa ( categoryDict [itemCategory ])
394+ categoryCode := getSpecialCategory ( categoryDict [itemCategory ], itemCategory )
393395 for _ , p := range matchingItem .Prices {
394- if p .LocationGroupId != nil && * p .LocationGroupId == 0 &&
395- len (p .Categories ) > 0 && p .Categories [0 ].CategoryCode != nil &&
396+ if isDefaultPrice (p ) && len (p .Categories ) > 0 && p .Categories [0 ].CategoryCode != nil &&
396397 * p .Categories [0 ].CategoryCode == categoryCode {
397-
398- PriceIdList = append (PriceIdList , * p .Id )
398+ priceId = * p .Id
399399 }
400400 }
401- priceId = PriceIdList [0 ]
401+ if priceId == 0 {
402+ subs := map [string ]interface {}{"Item" : itemKeyname , "Package" : packageKeyname , "Category" : categoryCode }
403+ return nil , errors .New (
404+ T ("Item {{.Item}} does not exist for package {{.Package}} with category {{.Category}}" , subs ))
405+ }
406+
402407 }
403408 prices = append (prices , priceId )
404409 }
@@ -491,3 +496,28 @@ func (i orderManager) GetAllCancelation(mask string) ([]datatypes.Billing_Item_C
491496func (i orderManager ) DeleteQuote (quoteId int ) (datatypes.Billing_Order_Quote , error ) {
492497 return i .BillingOrderQuoteService .Id (quoteId ).DeleteQuote ()
493498}
499+
500+ func getSpecialCategory (index int , base string ) string {
501+ // Special case because its disk_controller and disk_controller1
502+ // unlike gpu0/pci0 -> gpu1/pci1
503+ if base == "disk_controller" {
504+ if index == 0 {
505+ return base
506+ } else {
507+ return fmt .Sprintf ("%s1" , base )
508+ }
509+ }
510+ categoryCode := base [:len (base )- 1 ] + strconv .Itoa (index )
511+ return categoryCode
512+ }
513+
514+ func isDefaultPrice (price datatypes.Product_Item_Price ) bool {
515+ if price .LocationGroupId != nil && * price .LocationGroupId > 0 {
516+ return false
517+ } else {
518+ if price .Id != nil {
519+ return true
520+ }
521+ }
522+ return false
523+ }
0 commit comments