11using Dynamicweb . Content ;
2+ using Dynamicweb . Core ;
23using Dynamicweb . DataIntegration . EndpointManagement ;
34using Dynamicweb . Ecommerce . DynamicwebLiveIntegration . Configuration ;
45using Dynamicweb . Ecommerce . DynamicwebLiveIntegration . Connectors ;
1112using Dynamicweb . Rendering ;
1213using Dynamicweb . Security . UserManagement ;
1314using System ;
14- using System . Collections ;
1515using System . Collections . Generic ;
1616using System . Globalization ;
1717using System . Linq ;
@@ -29,7 +29,7 @@ namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration
2929 [ AddInIgnore ( false ) ]
3030 [ AddInUseParameterGrouping ( true ) ]
3131 [ AddInUseParameterOrdering ( true ) ]
32- public class LiveIntegrationAddIn : BaseLiveIntegrationAddIn , IDropDownOptions , ISettings
32+ public class LiveIntegrationAddIn : BaseLiveIntegrationAddIn , IParameterOptions , ISettings , IParameterVisibility
3333 {
3434 /// <summary>
3535 /// Initializes a new instance of the <see cref="LiveIntegrationAddIn"/> class.
@@ -77,12 +77,19 @@ public LiveIntegrationAddIn()
7777 [ AddInParameterOrder ( 6 ) ]
7878 public string InstanceLabel { get ; set ; }
7979
80+ [ AddInParameterGroup ( "General" ) ]
81+ [ AddInParameter ( "ConnectionToType" ) ]
82+ [ AddInLabel ( "Connect to" ) ]
83+ [ AddInParameterEditor ( typeof ( RadioParameterEditor ) , "" ) ]
84+ [ AddInParameterOrder ( 9 ) ]
85+ public string ConnectionToType { get ; set ; } = nameof ( ConnectionType . Endpoint ) ;
86+
8087 /// <summary>
8188 /// The web service Uri
8289 /// </summary>
8390 /// <value>The web service URI.</value>
8491 [ AddInParameter ( "Web service URL" ) ]
85- [ AddInParameterEditor ( typeof ( TextParameterEditor ) , "TextArea=True" ) ]
92+ [ AddInParameterEditor ( typeof ( TextParameterEditor ) , "TextArea=True; " ) ]
8693 [ AddInParameterGroup ( "General" ) ]
8794 [ AddInParameterOrder ( 10 ) ]
8895 public override string WebServiceURI { get ; set ; }
@@ -92,7 +99,7 @@ public LiveIntegrationAddIn()
9299 /// </summary>
93100 /// <value>The security key.</value>
94101 [ AddInParameter ( "Security key" ) ]
95- [ AddInParameterEditor ( typeof ( TextParameterEditor ) , "password=true" ) ]
102+ [ AddInParameterEditor ( typeof ( TextParameterEditor ) , "password=true; " ) ]
96103 [ AddInParameterGroup ( "General" ) ]
97104 [ AddInParameterOrder ( 20 ) ]
98105 public override string SecurityKey { get ; set ; }
@@ -102,7 +109,7 @@ public LiveIntegrationAddIn()
102109 /// </summary>
103110 /// <value>The Endpoint id.</value>
104111 [ AddInParameter ( "Endpoint" ) ]
105- [ AddInParameterEditor ( typeof ( DropDownParameterEditor ) , "multiple=true; none=true;InfoBar=true;Tooltip=Only works with a web service exposed by a plug-in unit from Dynamicweb. This option takes precedence " ) ]
112+ [ AddInParameterEditor ( typeof ( DropDownParameterEditor ) , "none=true;InfoBar=true;explanation=Select endpoint exposing a plug-in unit from Dynamicweb" ) ]
106113 [ AddInParameterGroup ( "General" ) ]
107114 [ AddInParameterOrder ( 20 ) ]
108115 public string Endpoint { get ; set ; }
@@ -177,7 +184,7 @@ public LiveIntegrationAddIn()
177184 /// </summary>
178185 /// <value><c>true</c> if [enable live prices]; otherwise, <c>false</c>.</value>
179186 [ AddInParameter ( "Enable live prices" ) ]
180- [ AddInParameterEditor ( typeof ( YesNoParameterEditor ) , "" ) ]
187+ [ AddInParameterEditor ( typeof ( YesNoParameterEditor ) , "reloadonchange=true; " ) ]
181188 [ AddInParameterGroup ( "Products" ) ]
182189 [ AddInParameterOrder ( 63 ) ]
183190 public bool EnableLivePrices { get ; set ; } = true ;
@@ -494,7 +501,7 @@ public LiveIntegrationAddIn()
494501 /// </summary>
495502 /// <value>The notification email.</value>
496503 [ AddInParameter ( "Notification recipient groups" ) ]
497- [ AddInParameterEditor ( typeof ( UserGroupParameterEditor ) , "Multiple=true;" ) ]
504+ [ AddInParameterEditor ( typeof ( UserGroupParameterEditor ) , "Multiple=true;" ) ]
498505 [ AddInParameterGroup ( "Notifications" ) ]
499506 [ AddInParameterOrder ( 235 ) ]
500507 public string RecipientGroups { get ; set ; }
@@ -621,66 +628,66 @@ public LiveIntegrationAddIn()
621628 /// </summary>
622629 /// <param name="dropdownName">Name of the dropdown.</param>
623630 /// <returns>Hashtable.</returns>
624- public Hashtable GetOptions ( string dropdownName )
631+ IEnumerable < ParameterOption > IParameterOptions . GetParameterOptions ( string dropdownName )
625632 {
626- var options = new Hashtable ( ) ;
633+ var options = new List < ParameterOption > ( ) ;
627634
628635 switch ( dropdownName )
629636 {
630637 case "Notification sending frequency" :
631638 foreach ( NotificationFrequency frequencyLevel in Enum . GetValues ( typeof ( NotificationFrequency ) ) )
632639 {
633- options . Add ( ( ( int ) frequencyLevel ) . ToString ( ) , GetNotificationFrequencyText ( frequencyLevel ) ) ;
640+ options . Add ( new ( GetNotificationFrequencyText ( frequencyLevel ) , ( ( int ) frequencyLevel ) . ToString ( ) ) ) ;
634641 }
635642 break ;
636643
637644 case "Order state after export succeeded" :
638645 case "Order state after export failed" :
639- options . Add ( string . Empty , "Leave unchanged" ) ;
646+ options . Add ( new ( "Leave unchanged" , string . Empty ) ) ;
640647 foreach ( var state in Services . OrderStates . GetStatesByOrderType ( OrderType . Order ) )
641648 {
642649 if ( state . IsDeleted )
643650 continue ;
644651
645- options . Add ( state . Id , state . GetName ( Services . Languages . GetDefaultLanguageId ( ) ) ) ;
652+ options . Add ( new ( state . GetName ( Services . Languages . GetDefaultLanguageId ( ) ) , state . Id ) ) ;
646653 }
647654 break ;
648655
649656 case "Shop" :
650- options . Add ( string . Empty , "Any" ) ;
657+ options . Add ( new ( "Any" , string . Empty ) ) ;
651658 var shops = Services . Shops . GetShops ( ) ;
652659 foreach ( var shop in shops )
653660 {
654- options . Add ( shop . Id , shop . Name ) ;
661+ options . Add ( new ( shop . Name , shop . Id ) ) ;
655662 }
656663 break ;
657664 case "Website" :
658665 foreach ( var area in new AreaService ( ) . GetAreas ( ) )
659666 {
660- options . Add ( area . ID , area . Name ) ;
667+ options . Add ( new ( area . Name , area . ID ) ) ;
661668 }
662669 break ;
663670 case "Cart communication type" :
664- options . Add ( Constants . CartCommunicationType . None , Constants . CartCommunicationType . None ) ;
665- options . Add ( Constants . CartCommunicationType . Full , Constants . CartCommunicationType . Full ) ;
666- options . Add ( Constants . CartCommunicationType . OnlyOnOrderComplete , Constants . CartCommunicationType . OnlyOnOrderComplete ) ;
667- options . Add ( Constants . CartCommunicationType . CartOnly , Constants . CartCommunicationType . CartOnly ) ;
671+ options . Add ( new ( Constants . CartCommunicationType . None , Constants . CartCommunicationType . None ) ) ;
672+ options . Add ( new ( Constants . CartCommunicationType . Full , Constants . CartCommunicationType . Full ) ) ;
673+ options . Add ( new ( Constants . CartCommunicationType . OnlyOnOrderComplete , Constants . CartCommunicationType . OnlyOnOrderComplete ) ) ;
674+ options . Add ( new ( Constants . CartCommunicationType . CartOnly , Constants . CartCommunicationType . CartOnly ) ) ;
668675 break ;
669676
670677 case "Number format culture" :
671678 foreach ( CultureInfo culture in CultureInfo . GetCultures ( CultureTypes . AllCultures ) )
672679 {
673- if ( ! string . IsNullOrEmpty ( culture . Name ) && ! culture . IsNeutralCulture && ! options . ContainsKey ( culture . Name ) )
680+ if ( ! string . IsNullOrEmpty ( culture . Name ) && ! culture . IsNeutralCulture && ! options . Any ( o => string . Equals ( o . Value . ToString ( ) , culture . Name , StringComparison . OrdinalIgnoreCase ) ) )
674681 {
675- options . Add ( culture . Name , $ "{ culture . Name } - { culture . EnglishName } ") ;
682+ options . Add ( new ( $ "{ culture . Name } - { culture . EnglishName } ", culture . Name ) ) ;
676683 }
677684 }
678685 break ;
679686 case "Order cache level" :
680687 case "Product information cache level" :
681688 foreach ( var cacheLevel in Enum . GetNames ( typeof ( Cache . ResponseCacheLevel ) ) )
682689 {
683- options . Add ( cacheLevel , cacheLevel ) ;
690+ options . Add ( new ( cacheLevel , cacheLevel ) ) ;
684691 }
685692 break ;
686693 case "Endpoint" :
@@ -708,20 +715,24 @@ public Hashtable GetOptions(string dropdownName)
708715 if ( endpointFilters . ContainsKey ( endpoint . Id ) )
709716 {
710717 string str = endpointFilters [ endpoint . Id ] ;
711- options . Add ( str , endpoint . Name + str . Substring ( str . IndexOf ( ";" ) ) ) ;
718+ options . Add ( new ( endpoint . Name + str . Substring ( str . IndexOf ( ";" ) ) , str ) ) ;
712719 }
713720 else
714721 {
715- options . Add ( endpoint . Id . ToString ( ) , endpoint . Name ) ;
722+ options . Add ( new ( endpoint . Name , endpoint . Id . ToString ( ) ) ) ;
716723 }
717724 }
718725 break ;
719726 case "ERP shipping item type" :
720- options . Add ( Constants . OrderConfiguration . DefaultShippingItemType , "Item Charge" ) ;
721- options . Add ( "Account" , "G/L Account" ) ;
722- options . Add ( "Item" , "Item" ) ;
723- options . Add ( "FixedAsset" , "Fixed Asset" ) ;
724- options . Add ( "Resource" , "Resource" ) ;
727+ options . Add ( new ( "Item Charge" , Constants . OrderConfiguration . DefaultShippingItemType ) ) ;
728+ options . Add ( new ( "G/L Account" , "Account" ) ) ;
729+ options . Add ( new ( "Item" , "Item" ) ) ;
730+ options . Add ( new ( "Fixed Asset" , "FixedAsset" ) ) ;
731+ options . Add ( new ( "Resource" , "Resource" ) ) ;
732+ break ;
733+ case "ConnectionToType" :
734+ options . Add ( new ( nameof ( ConnectionType . Endpoint ) , ConnectionType . Endpoint ) ) ;
735+ options . Add ( new ( "Dynamicweb connector web service" , ConnectionType . WebService ) ) ;
725736 break ;
726737 default :
727738 throw new ArgumentException ( $ "Unsupported dropdown: { dropdownName } ", nameof ( dropdownName ) ) ;
@@ -730,6 +741,40 @@ public Hashtable GetOptions(string dropdownName)
730741 return options ;
731742 }
732743
744+ IEnumerable < string > IParameterVisibility . GetHiddenParameterNames ( string parameterName , object parameterValue )
745+ {
746+ var result = new List < string > ( ) ;
747+ var parameterValueStr = Converter . ToString ( parameterValue ) ;
748+ switch ( parameterName )
749+ {
750+ case nameof ( ConnectionToType ) :
751+ if ( nameof ( ConnectionType . Endpoint ) . Equals ( parameterValueStr , StringComparison . OrdinalIgnoreCase ) )
752+ {
753+ result . Add ( "Web service URL" ) ;
754+ result . Add ( "Security key" ) ;
755+ }
756+ else
757+ {
758+ result . Add ( "Endpoint" ) ;
759+ }
760+ break ;
761+ case "Enable live prices" :
762+ if ( Converter . ToBoolean ( parameterValue ) is false )
763+ {
764+ result . Add ( "Lazy load product info (&getproductinfo=true)" ) ;
765+ result . Add ( "Include product custom fields in request" ) ;
766+ result . Add ( "Product information cache level" ) ;
767+ result . Add ( "Use product number in price calculation" ) ;
768+ result . Add ( "Use unit prices" ) ;
769+ result . Add ( "Retry request for the product information" ) ;
770+ result . Add ( "Include variants in the product information request" ) ;
771+ result . Add ( "Max products per request" ) ;
772+ }
773+ break ;
774+ }
775+ return result ;
776+ }
777+
733778 private Settings GetCurrentSettings ( )
734779 {
735780 Settings settings = null ;
@@ -781,6 +826,11 @@ public override string LoadSettings()
781826 Settings settings = GetCurrentSettings ( ) ;
782827 Settings . UpdateFrom ( settings , this ) ;
783828
829+ if ( string . IsNullOrEmpty ( Endpoint ) && ! string . IsNullOrEmpty ( WebServiceURI ) )
830+ {
831+ ConnectionToType = nameof ( ConnectionType . WebService ) ;
832+ }
833+
784834 var xml = GetParametersToXml ( false ) ;
785835
786836 return xml ;
@@ -792,6 +842,13 @@ public override string LoadSettings()
792842 public override void SaveSettings ( )
793843 {
794844 Settings settings = GetCurrentSettings ( ) ;
845+ // Do not allow Endpoint and WebService to be selected at the same time
846+ if ( ! string . IsNullOrEmpty ( Endpoint ) && ! string . IsNullOrEmpty ( WebServiceURI )
847+ && Enum . TryParse < ConnectionType > ( ConnectionToType , out var connectionType ) && connectionType == ConnectionType . WebService )
848+ {
849+ Endpoint = "" ;
850+ }
851+
795852 Settings . UpdateFrom ( this , settings ) ;
796853 if ( string . IsNullOrEmpty ( settings . InstanceId ) )
797854 {
@@ -807,7 +864,7 @@ public override void SaveSettings()
807864 {
808865 AutoPingInterval = Constants . MinPingInterval ;
809866 }
810- if ( ConnectionTimeout < Constants . DefaultConnectionTimeout )
867+ if ( ConnectionTimeout < Constants . DefaultConnectionTimeout )
811868 {
812869 ConnectionTimeout = Constants . DefaultConnectionTimeout ;
813870 }
@@ -930,5 +987,11 @@ private static void SaveTranslations(Settings settings)
930987 Helpers . SaveTranslation ( Constants . OrderConfiguration . OrderDiscountText , settings . OrderDiscountText ) ;
931988 Helpers . SaveTranslation ( Constants . OrderConfiguration . ProductDiscountText , settings . ProductDiscountText ) ;
932989 }
990+
991+ private enum ConnectionType
992+ {
993+ Endpoint ,
994+ WebService ,
995+ }
933996 }
934997}
0 commit comments