@@ -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,17 @@ 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 ,
316+ } else if len (p .Messages ) > 0 {
317+ defaultMessagesConfiguration := platform.MessagesConfigurationDraft {
318+ DeleteDaysAfterCreation : DefaultMessagesDeleteDaysAfterCreation ,
319+ }
320+ if ! reflect .DeepEqual (p .Messages [0 ].toNative (), defaultMessagesConfiguration ) {
321+ result .Actions = append (result .Actions ,
322+ platform.ProjectChangeMessagesConfigurationAction {
323+ MessagesConfiguration : defaultMessagesConfiguration ,
317324 },
318- },
319- )
325+ )
326+ }
320327 }
321328 }
322329
@@ -491,7 +498,7 @@ type Messages struct {
491498}
492499
493500func (m Messages ) toNative () platform.MessagesConfigurationDraft {
494- days := DefaultDeleteDaysAfterCreation // Commercetools default
501+ days := DefaultMessagesDeleteDaysAfterCreation // Commercetools default
495502
496503 if ! m .DeleteDaysAfterCreation .IsNull () {
497504 days = int (m .DeleteDaysAfterCreation .ValueInt64 ())
@@ -503,7 +510,7 @@ func (m Messages) toNative() platform.MessagesConfigurationDraft {
503510 }
504511}
505512func (m Messages ) isDefault () bool {
506- return ! m .toNative ().Enabled && m .DeleteDaysAfterCreation .ValueInt64 () == DefaultDeleteDaysAfterCreation
513+ return ! m .toNative ().Enabled && m .DeleteDaysAfterCreation .ValueInt64 () == DefaultMessagesDeleteDaysAfterCreation
507514}
508515
509516type ExternalOAuth struct {
@@ -527,7 +534,7 @@ type Carts struct {
527534
528535func (c Carts ) isDefault () bool {
529536 return ! c .CountryTaxRateFallbackEnabled .ValueBool () &&
530- c .DeleteDaysAfterLastModification .ValueInt64 () == DefaultDaysAfterLastModification &&
537+ c .DeleteDaysAfterLastModification .ValueInt64 () == DefaultCartsDeleteDaysAfterLastModification &&
531538 (c .PriceRoundingMode .IsNull () || c .PriceRoundingMode .ValueString () == string (platform .RoundingModeHalfEven )) &&
532539 (c .TaxRoundingMode .IsNull () || c .TaxRoundingMode .ValueString () == string (platform .RoundingModeHalfEven ))
533540}
@@ -537,7 +544,7 @@ func (c Carts) toNative() platform.CartsConfiguration {
537544 taxRoundingMode := platform .RoundingMode (c .TaxRoundingMode .ValueString ())
538545
539546 return platform.CartsConfiguration {
540- DeleteDaysAfterLastModification : utils . OptionalInt (c .DeleteDaysAfterLastModification ),
547+ DeleteDaysAfterLastModification : int (c .DeleteDaysAfterLastModification . ValueInt64 () ),
541548 CountryTaxRateFallbackEnabled : utils .BoolRef (c .CountryTaxRateFallbackEnabled .ValueBool ()),
542549 PriceRoundingMode : & priceRoundingMode ,
543550 TaxRoundingMode : & taxRoundingMode ,
@@ -549,12 +556,12 @@ type ShoppingList struct {
549556}
550557
551558func (c ShoppingList ) isDefault () bool {
552- return c .DeleteDaysAfterLastModification .ValueInt64 () == DefaultDaysAfterLastModification
559+ return c .DeleteDaysAfterLastModification .ValueInt64 () == DefaultShoppingListsDeleteDaysAfterLastModification
553560}
554561
555562func (c ShoppingList ) toNative () platform.ShoppingListsConfiguration {
556563 return platform.ShoppingListsConfiguration {
557- DeleteDaysAfterLastModification : utils . OptionalInt (c .DeleteDaysAfterLastModification ),
564+ DeleteDaysAfterLastModification : int (c .DeleteDaysAfterLastModification . ValueInt64 () ),
558565 }
559566}
560567
0 commit comments