Skip to content

Commit

Permalink
[feature] Added hyperlinks for marketplaces
Browse files Browse the repository at this point in the history
  • Loading branch information
anion0278 committed Mar 13, 2023
1 parent 76b2b0f commit a4eee55
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 77 deletions.
26 changes: 21 additions & 5 deletions Mapp.DataAccess/StockQuantityUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Text.RegularExpressions;
using System.Xml;
using System;
using System.Linq;
using System.Threading.Tasks;
using Shmap.CommonServices;

namespace Shmap.DataAccess;

Expand All @@ -17,27 +19,41 @@ public interface IStockQuantityUpdater
public class StockQuantityUpdater : IStockQuantityUpdater
{
private readonly IJsonManager _jsonManager;
private readonly IDialogService _dialogService;
private readonly IEnumerable<StockDataXmlSourceDefinition> _sourceDefinitions;

public StockQuantityUpdater(IJsonManager jsonManager)
public StockQuantityUpdater(IJsonManager jsonManager, IDialogService dialogService)
{
_jsonManager = jsonManager;
_dialogService = dialogService;
_sourceDefinitions = _jsonManager.LoadStockQuantityUpdaterConfigs();
}

public async Task<IEnumerable<StockData>> ConvertWarehouseData()
{

var httpClient = new HttpClient();

var stockData = new List<StockData>();
var stockDataTotal = new List<StockData>();

Dictionary<string, int> statistics = new Dictionary<string, int>();

foreach (var source in _sourceDefinitions)
{
var stream = await (await httpClient.GetAsync(source.Url)).Content.ReadAsStreamAsync();
stockData.AddRange(ExtractStockData(stream, source));
var stockData = ExtractStockData(stream, source);
stockDataTotal.AddRange(stockData);

statistics.Add(source.Url, stockData.Count());
}

return stockData;
string msg = "Konvertovano:\n";
foreach (var (url, count) in statistics)
{
msg += $"{count} zaznamu z: {url} \n";
}
_dialogService.ShowMessage(msg);

return stockDataTotal;
}

private IEnumerable<StockData> ExtractStockData(Stream stream, StockDataXmlSourceDefinition source)
Expand Down
1 change: 1 addition & 0 deletions Mapp.UI/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private void ConfigureContainer()
Container.RegisterTypeAsSingleton<IMainWindowViewModel, MainWindowViewModel>();
Container.RegisterTypeAsSingleton<IDialogService, DialogService>();
Container.RegisterTypeAsSingleton<IStockQuantityUpdater, StockQuantityUpdater>();
Container.RegisterTypeAsSingleton<IBrowserService, BrowserService>();

Container.RegisterType<IManualChangeWindowViewModel, ManualChangeWindowViewModel>();

Expand Down
18 changes: 18 additions & 0 deletions Mapp.UI/BrowserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Diagnostics;
using System;


namespace Shmap.UI;

public interface IBrowserService
{
void OpenBrowserOnUrl(string url);
}

public class BrowserService : IBrowserService
{
public void OpenBrowserOnUrl(string url)
{
Process.Start(new ProcessStartInfo(url.ToString()) { UseShellExecute = true });
}
}
7 changes: 5 additions & 2 deletions Mapp.UI/ViewModels/InvoiceItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
using GalaSoft.MvvmLight.CommandWpf;
using Shmap.CommonServices;
using Shmap.DataAccess;
using Shmap.UI;
using NLog.LayoutRenderers;

namespace Shmap.ViewModels
{
public class InvoiceItemViewModel : ViewModelWithErrorValidationBase
{
private readonly InvoiceItemBase _model;
private readonly IBrowserService _browserService;
private readonly IAutocompleteData _autocompleteData;
private string _amazonProductName;
private string _warehouseProductCode;
Expand Down Expand Up @@ -69,7 +71,7 @@ public uint? PackQuantityMultiplier
}
}

public InvoiceItemViewModel(InvoiceItemBase model, IAutocompleteData autocompleteData)
public InvoiceItemViewModel(InvoiceItemBase model, IAutocompleteData autocompleteData, IBrowserService browserService)
{
AmazonNumber = model.ParentInvoice.VariableSymbolFull;
SalesChannel = model.ParentInvoice.SalesChannel;
Expand All @@ -96,6 +98,7 @@ public InvoiceItemViewModel(InvoiceItemBase model, IAutocompleteData autocomplet

// temp
_model = model;
_browserService = browserService;
}

private void GoToInvoicePage() // TODO into separate provider + tests
Expand All @@ -112,7 +115,7 @@ private void GoToInvoicePage() // TODO into separate provider + tests
?? defaultAmazonCentralUrl;

url += AmazonNumber;
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
_browserService.OpenBrowserOnUrl(url);
}

private bool ValidateProductCode()
Expand Down
52 changes: 16 additions & 36 deletions Mapp.UI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
using System.Net.Http;
using System.Net.Mail;
using System.Reflection;
using System.Security.Policy;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Xml;
using Castle.Core.Internal;
using GalaSoft.MvvmLight.CommandWpf;
Expand All @@ -40,6 +40,7 @@ internal class MainWindowViewModel : ViewModelWithErrorValidationBase, IMainWind
private readonly ITransactionsReader _transactionsReader;
private readonly IGpcGenerator _gpcGenerator;
private readonly IAutocompleteData _autocompleteData;
private readonly IBrowserService _browserService;
private readonly IStockQuantityUpdater _quantityUpdater;
private readonly IDialogService _dialogService;
private int _windowWidth;
Expand All @@ -57,6 +58,7 @@ internal class MainWindowViewModel : ViewModelWithErrorValidationBase, IMainWind
public RelayCommand ExportConvertedAmazonInvoicesCommand { get; }
public RelayCommand ConvertTransactionsCommand { get; }
public RelayCommand ConvertWarehouseDataCommand { get; set; }
public RelayCommand<string> OpenAmazonMarketPlaceUriCommand { get; set; }

public ObservableCollection<InvoiceItemViewModel> InvoiceItems { get; } = new(); // TODO make private field?

Expand Down Expand Up @@ -206,7 +208,7 @@ public MainWindowViewModel() // Design-time ctor
var dataMock = Mock.Of<IAutocompleteData>();
foreach (var item in items)
{
InvoiceItems.Add(new InvoiceItemViewModel(item, dataMock)); // TODO create bindable collection with AddRange method
InvoiceItems.Add(new InvoiceItemViewModel(item, dataMock, new BrowserService())); // TODO create bindable collection with AddRange method
}
Invoices.Add(new InvoiceViewModel(invoice, dataMock));
}
Expand All @@ -217,6 +219,7 @@ public MainWindowViewModel(IConfigProvider configProvider,
ITransactionsReader transactionsReader,
IGpcGenerator gpcGenerator,
IAutocompleteData autocompleteData,
IBrowserService browserService,
IStockQuantityUpdater quantityUpdater,
IDialogService dialogService)
{
Expand All @@ -226,13 +229,15 @@ public MainWindowViewModel(IConfigProvider configProvider,
_transactionsReader = transactionsReader;
_gpcGenerator = gpcGenerator;
_autocompleteData = autocompleteData;
_browserService = browserService;
_quantityUpdater = quantityUpdater;
_dialogService = dialogService;

SelectAmazonInvoicesCommand = new RelayCommand(SelectAmazonInvoices, () => !HasErrors);
ExportConvertedAmazonInvoicesCommand = new RelayCommand(ExportConvertedAmazonInvoices, ExportConvertedAmazonInvoicesCanExecute);
ConvertTransactionsCommand = new RelayCommand(ConvertTransactions, () => true);
ConvertWarehouseDataCommand = new RelayCommand(ConvertWarehouseData, () => true);
OpenAmazonMarketPlaceUriCommand = new RelayCommand<string>(OpenAmazonMarketPlaceUri);

InvoiceItemsCollectionView = InitializeCollectionView();

Expand All @@ -251,43 +256,17 @@ public MainWindowViewModel(IConfigProvider configProvider,
}


private void OpenAmazonMarketPlaceUri(string uri)
{
_browserService.OpenBrowserOnUrl(uri);
}


private async void ConvertWarehouseData()
{
IsReadyForProcessing = false;
try
{
//StockDataXmlSourceDefinition[] sources =
//{
// new()
// {
// Url = "https://www.rappa.cz/export/vo.xml",
// ItemNodeName = "SHOPITEM",
// SkuNodeParsingOptions = new[]
// {
// new ValueParsingOption("EAN", null),
// },
// StockQuantityNodeParsingOptions = new[]
// {
// new ValueParsingOption("STOCK", null),
// },
// },
// new()
// {
// Url = "https://en.bushman.eu/content/feeds/uQ5TueFNQh_expando_4.xml",
// ItemNodeName = "item",
// SkuNodeParsingOptions = new[]
// {
// new ValueParsingOption("g:gtin", null),
// new ValueParsingOption("g:sku_with_ean", @"\d{13}"),
// },
// StockQuantityNodeParsingOptions = new[]
// {
// new ValueParsingOption("g:quantity", null),
// },
// }
//};


var stockData = await _quantityUpdater.ConvertWarehouseData();
var columnNamesLine =
"sku\tprice\tminimum-seller-allowed-price\tmaximum-seller-allowed-price\tquantity\thandling-time\tfulfillment-channel";
Expand Down Expand Up @@ -380,7 +359,7 @@ private void SelectAmazonInvoices()

foreach (var invoiceItem in invoices.SelectMany(di => di.InvoiceItems))
{
InvoiceItems.Add(new InvoiceItemViewModel(invoiceItem, _autocompleteData));
InvoiceItems.Add(new InvoiceItemViewModel(invoiceItem, _autocompleteData, _browserService));
}

foreach (var invoice in invoices)
Expand All @@ -395,8 +374,9 @@ private void ExportConvertedAmazonInvoices()
if (string.IsNullOrWhiteSpace(fileName)) return;

var invoices = Invoices.Select(i => i.ExportModel()).ToList();
var invoiceItems = InvoiceItems.Select(i => i.ExportModel()).ToList();

// TODO how to avoid need for calling ToList (due to laziness of linq)?
var invoiceItems = InvoiceItems.Select(i => i.ExportModel()).ToList();

if (!invoices.Any())
{
Expand Down
17 changes: 16 additions & 1 deletion Mapp.UI/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
</DataTrigger>
</Style.Triggers>


</Style>

<Style x:Key="ProductCodeToggleableReadonlyCellStyle" TargetType="{x:Type DataGridCell}"
Expand Down Expand Up @@ -351,6 +351,21 @@
</Style>
</Button.Style>
</Button>
<TextBlock HorizontalAlignment="Center" Margin="10">
<Hyperlink CommandParameter="https://sellercentral.amazon.ca/listing/upload?ref_=xx_upload_tnav_status" Command="{Binding OpenAmazonMarketPlaceUriCommand}">
Amazon CA
</Hyperlink>
</TextBlock>
<TextBlock HorizontalAlignment="Center" Margin="10">
<Hyperlink CommandParameter="https://sellercentral.amazon.com/listing/upload?ref_=xx_upload_tnav_status" Command="{Binding OpenAmazonMarketPlaceUriCommand}">
Amazon USA
</Hyperlink>
</TextBlock>
<TextBlock HorizontalAlignment="Center" Margin="10">
<Hyperlink CommandParameter="https://sellercentral.amazon.de/listing/upload?ref_=xx_upload_tnav_status" Command="{Binding OpenAmazonMarketPlaceUriCommand}">
Amazon DE
</Hyperlink>
</TextBlock>
</StackPanel>
</Grid>
</TabItem>
Expand Down
33 changes: 0 additions & 33 deletions Mapp.UI/azure-pipelines.yml

This file was deleted.

0 comments on commit a4eee55

Please sign in to comment.