@@ -13,8 +13,9 @@ import (
1313)
1414
1515const (
16- DefaultDeleteDaysAfterCreation = 15
17- DefaultDaysAfterLastModification = 90
16+ DefaultMessagesDeleteDaysAfterCreation = 15
17+ DefaultCartsDeleteDaysAfterLastModification = 90
18+ DefaultShoppingListsDeleteDaysAfterLastModification = 360
1819)
1920
2021type Project struct {
@@ -52,7 +53,7 @@ func IsDefaultShoppingListsConfiguration(c *platform.ShoppingListsConfiguration)
5253 return true
5354 }
5455
55- return c .DeleteDaysAfterLastModification == nil || * c .DeleteDaysAfterLastModification == DefaultDaysAfterLastModification
56+ return c .DeleteDaysAfterLastModification == 0 || c .DeleteDaysAfterLastModification == DefaultShoppingListsDeleteDaysAfterLastModification
5657}
5758
5859func NewProjectFromNative (n * platform.Project ) Project {
@@ -81,9 +82,14 @@ func NewProjectFromNative(n *platform.Project) Project {
8182 BusinessUnits : []BusinessUnits {},
8283 }
8384
85+ var cartsDeleteDaysAfterLastModification = DefaultCartsDeleteDaysAfterLastModification
86+ if n .Carts .DeleteDaysAfterLastModification != 0 {
87+ cartsDeleteDaysAfterLastModification = n .Carts .DeleteDaysAfterLastModification
88+ }
89+
8490 res .Carts = []Carts {
8591 {
86- DeleteDaysAfterLastModification : utils . FromOptionalInt ( n . Carts . DeleteDaysAfterLastModification ),
92+ DeleteDaysAfterLastModification : types . Int64Value ( int64 ( cartsDeleteDaysAfterLastModification ) ),
8793 CountryTaxRateFallbackEnabled : utils .FromOptionalBool (n .Carts .CountryTaxRateFallbackEnabled ),
8894 PriceRoundingMode : utils .FromOptionalString ((* string )(n .Carts .PriceRoundingMode )),
8995 TaxRoundingMode : utils .FromOptionalString ((* string )(n .Carts .TaxRoundingMode )),
@@ -93,7 +99,7 @@ func NewProjectFromNative(n *platform.Project) Project {
9399 if ! IsDefaultShoppingListsConfiguration (n .ShoppingLists ) {
94100 res .ShoppingLists = []ShoppingList {
95101 {
96- DeleteDaysAfterLastModification : utils . FromOptionalInt ( n .ShoppingLists .DeleteDaysAfterLastModification ),
102+ DeleteDaysAfterLastModification : types . Int64Value ( int64 ( n .ShoppingLists .DeleteDaysAfterLastModification ) ),
97103 },
98104 }
99105 }
@@ -118,7 +124,7 @@ func NewProjectFromNative(n *platform.Project) Project {
118124 // If delete_days_after_creation is nil (before version 1.6) then we set it
119125 // to the commercetools default of 15
120126 if res .Messages [0 ].DeleteDaysAfterCreation .IsNull () {
121- res .Messages [0 ].DeleteDaysAfterCreation = types .Int64Value (DefaultDeleteDaysAfterCreation )
127+ res .Messages [0 ].DeleteDaysAfterCreation = types .Int64Value (DefaultMessagesDeleteDaysAfterCreation )
122128 }
123129
124130 if n .SearchIndexing != nil && n .SearchIndexing .Products != nil && n .SearchIndexing .Products .Status != nil {
@@ -188,7 +194,7 @@ func (p *Project) setStateData(o Project) {
188194
189195 // The commercetools default for delete_days_after_creation is 15, so if the
190196 if len (p .Messages ) > 0 && len (o .Messages ) > 0 {
191- if p .Messages [0 ].DeleteDaysAfterCreation .ValueInt64 () == DefaultDeleteDaysAfterCreation && o .Messages [0 ].DeleteDaysAfterCreation .IsNull () {
197+ if p .Messages [0 ].DeleteDaysAfterCreation .ValueInt64 () == DefaultCartsDeleteDaysAfterLastModification && o .Messages [0 ].DeleteDaysAfterCreation .IsNull () {
192198 p .Messages [0 ].DeleteDaysAfterCreation = o .Messages [0 ].DeleteDaysAfterCreation
193199 }
194200 }
@@ -214,7 +220,7 @@ func (p *Project) updateActions(plan Project) (platform.ProjectUpdate, error) {
214220 result .Actions = append (result .Actions ,
215221 platform.ProjectChangeCartsConfigurationAction {
216222 CartsConfiguration : platform.CartsConfiguration {
217- DeleteDaysAfterLastModification : utils . IntRef ( DefaultDaysAfterLastModification ) ,
223+ DeleteDaysAfterLastModification : DefaultCartsDeleteDaysAfterLastModification ,
218224 },
219225 },
220226 platform.ProjectChangeCountryTaxRateFallbackEnabledAction {
@@ -252,7 +258,7 @@ func (p *Project) updateActions(plan Project) (platform.ProjectUpdate, error) {
252258 result .Actions = append (result .Actions ,
253259 platform.ProjectChangeShoppingListsConfigurationAction {
254260 ShoppingListsConfiguration : platform.ShoppingListsConfiguration {
255- DeleteDaysAfterLastModification : utils . IntRef ( DefaultDaysAfterLastModification ) ,
261+ DeleteDaysAfterLastModification : DefaultShoppingListsDeleteDaysAfterLastModification ,
256262 },
257263 },
258264 )
@@ -307,16 +313,6 @@ func (p *Project) updateActions(plan Project) (platform.ProjectUpdate, error) {
307313 MessagesConfiguration : plan .Messages [0 ].toNative (),
308314 },
309315 )
310- } else {
311- // Set message configuration to the default values
312- result .Actions = append (result .Actions ,
313- platform.ProjectChangeMessagesConfigurationAction {
314- MessagesConfiguration : platform.MessagesConfigurationDraft {
315- Enabled : false ,
316- DeleteDaysAfterCreation : DefaultDeleteDaysAfterCreation ,
317- },
318- },
319- )
320316 }
321317 }
322318
@@ -491,7 +487,7 @@ type Messages struct {
491487}
492488
493489func (m Messages ) toNative () platform.MessagesConfigurationDraft {
494- days := DefaultDeleteDaysAfterCreation // Commercetools default
490+ days := DefaultMessagesDeleteDaysAfterCreation // Commercetools default
495491
496492 if ! m .DeleteDaysAfterCreation .IsNull () {
497493 days = int (m .DeleteDaysAfterCreation .ValueInt64 ())
@@ -503,7 +499,7 @@ func (m Messages) toNative() platform.MessagesConfigurationDraft {
503499 }
504500}
505501func (m Messages ) isDefault () bool {
506- return ! m .toNative ().Enabled && m .DeleteDaysAfterCreation .ValueInt64 () == DefaultDeleteDaysAfterCreation
502+ return ! m .toNative ().Enabled && m .DeleteDaysAfterCreation .ValueInt64 () == DefaultMessagesDeleteDaysAfterCreation
507503}
508504
509505type ExternalOAuth struct {
@@ -527,7 +523,7 @@ type Carts struct {
527523
528524func (c Carts ) isDefault () bool {
529525 return ! c .CountryTaxRateFallbackEnabled .ValueBool () &&
530- c .DeleteDaysAfterLastModification .ValueInt64 () == DefaultDaysAfterLastModification &&
526+ c .DeleteDaysAfterLastModification .ValueInt64 () == DefaultCartsDeleteDaysAfterLastModification &&
531527 (c .PriceRoundingMode .IsNull () || c .PriceRoundingMode .ValueString () == string (platform .RoundingModeHalfEven )) &&
532528 (c .TaxRoundingMode .IsNull () || c .TaxRoundingMode .ValueString () == string (platform .RoundingModeHalfEven ))
533529}
@@ -537,7 +533,7 @@ func (c Carts) toNative() platform.CartsConfiguration {
537533 taxRoundingMode := platform .RoundingMode (c .TaxRoundingMode .ValueString ())
538534
539535 return platform.CartsConfiguration {
540- DeleteDaysAfterLastModification : utils . OptionalInt (c .DeleteDaysAfterLastModification ),
536+ DeleteDaysAfterLastModification : int (c .DeleteDaysAfterLastModification . ValueInt64 () ),
541537 CountryTaxRateFallbackEnabled : utils .BoolRef (c .CountryTaxRateFallbackEnabled .ValueBool ()),
542538 PriceRoundingMode : & priceRoundingMode ,
543539 TaxRoundingMode : & taxRoundingMode ,
@@ -549,12 +545,12 @@ type ShoppingList struct {
549545}
550546
551547func (c ShoppingList ) isDefault () bool {
552- return c .DeleteDaysAfterLastModification .ValueInt64 () == DefaultDaysAfterLastModification
548+ return c .DeleteDaysAfterLastModification .ValueInt64 () == DefaultShoppingListsDeleteDaysAfterLastModification
553549}
554550
555551func (c ShoppingList ) toNative () platform.ShoppingListsConfiguration {
556552 return platform.ShoppingListsConfiguration {
557- DeleteDaysAfterLastModification : utils . OptionalInt (c .DeleteDaysAfterLastModification ),
553+ DeleteDaysAfterLastModification : int (c .DeleteDaysAfterLastModification . ValueInt64 () ),
558554 }
559555}
560556
0 commit comments