Bukimedia / PrestaSharp

CSharp .Net client library for the PrestaShop API via web service
GNU General Public License v3.0
154 stars 152 forks source link

Error updating stock product quantity #347

Closed miguelextremanet closed 5 years ago

miguelextremanet commented 5 years ago

Hello, I'm trying to update stock quantity in a created product from vb.net desktop application but I always get the same error:

My VB code:

 Public Function ActualizaProductoPrestashop(sku As String,  stock As Long) As String

        Dim ProductFactory As Bukimedia.PrestaSharp.Factories.ProductFactory = New Bukimedia.PrestaSharp.Factories.ProductFactory(pagina_web_tienda & "/api", API_KEY_PRESTASHOP, "")
      'buscamos por el campo referencia
        Dim dtn As Dictionary(Of String, String) = New Dictionary(Of String, String)
        dtn.Add("reference", sku)
        Dim PRODUCTOS As List(Of Bukimedia.PrestaSharp.Entities.product) = ProductFactory.GetByFilter(dtn, Nothing, Nothing)
        Dim Password As String = ""
        Dim ret As String = ""

        For Each P As Bukimedia.PrestaSharp.Entities.product In PRODUCTOS
            Try
                'stock factory 
                Dim StockAvailableFactory As Bukimedia.PrestaSharp.Factories.StockAvailableFactory = New Bukimedia.PrestaSharp.Factories.StockAvailableFactory(pagina_web_tienda & "/api", API_KEY_PRESTASHOP, Password)
                'stock disponible 
                Dim stockavailable As Bukimedia.PrestaSharp.Entities.stock_available = New Bukimedia.PrestaSharp.Entities.stock_available
                Dim dtnsearch As Dictionary(Of String, String) = New Dictionary(Of String, String)
                dtnsearch.Add("id_product", P.id)
                'buscamos el el stock disponible para actualizarlo 
                Dim currentstock As List(Of Bukimedia.PrestaSharp.Entities.stock_available) = StockAvailableFactory.GetByFilter(dtnsearch, Nothing, Nothing)
                'si existe se actuaiza con el nuevo stock 
                If (currentstock.Count > 0) Then
                    currentstock(0).quantity = stock
                   StockAvailableFactory.Update(currentstock(0))
                End If
                'todo ok 

            Catch ex As Exception
                'error metodo UPDATE  de StockAvailableFactory
                Form1.EscribirMensaje(ex.Message)
            End Try

        Next
        Return ret
    End Function

The error exception Message is always "StartIndex no puede ser inferior a cero. Nombre del parámetro: startIndex"

What is the best way to update, no only stock, but price, name and picture of product?

Thanks in advance

mowcixo commented 5 years ago

Hello @miguelextremanet, thanks for creating the issue, I just tested your code and yes, there is a bug. I'll investigate and let you know soon.

miguelextremanet commented 5 years ago

Hello @miguelextremanet, thanks for creating the issue, I just tested your code and yes, there is a bug. I'll investigate and let you know soon.

Thank you very much

mowcixo commented 5 years ago

Hello @miguelextremanet, it should be fixed now with v1.0.3 version we just released. Thank you!

About product editting, you have to do the same you made for editing stock, but with product, let me know if you need some code snippet to make it in our slack group: https://join.slack.com/t/prestasharp/shared_invite/enQtNTM2OTI1OTg0NzUyLTY4NDdkZDFmY2EwMGE4MTMzZjk5YzZiMTk3MzUwNzUxNTdhMWEwZjFjNDJiZTIyMjI0MDM0NTcwMzIzNGI0Njc at the #help topic.

miguelextremanet commented 5 years ago

Ok gracias Lo he probado y funciona perfectamente.

Saludos Miguel Angel

Enviado desde mi iPhone

El 29 mar 2019, a las 14:30, Moisés Gramary Barbosa notifications@github.com escribió:

Hello @miguelextremanet, it should be fixed now with v1.0.3 version we just released. Thank you!

About product editting, you have to do the same you made for editing stock, but with product, let me know if you need some code snippet to make it in our slack group: https://join.slack.com/t/prestasharp/shared_invite/enQtNTM2OTI1OTg0NzUyLTY4NDdkZDFmY2EwMGE4MTMzZjk5YzZiMTk3MzUwNzUxNTdhMWEwZjFjNDJiZTIyMjI0MDM0NTcwMzIzNGI0Njc at the #help topic.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

AlexNav1972 commented 5 years ago

Hola, sabeis de algun ejemplo para desarrollar un CRUD desde vb.net que conecte con una tienda en PS 1.7? Gracias

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.