GithubHelp home page GithubHelp logo

Comments (3)

nikkofu avatar nikkofu commented on September 27, 2024

I'm now testing the product create function, with the xml value from https://devdocs.prestashop-project.org/8/webservice/tutorials/create-product-az/

const PrestashopLanguageUsEn = 3
const PrestashopLanguageZhCN = 1

func BuildLanguageData(language ...prestashop.Language) *prestashop.LanguageData {
return &prestashop.LanguageData{
Language: &language,
}
}

func TestPrestashopProductCreate(t *testing.T) {

data := prestashop.Product{
	IDManufacturer:    1,
	IDSupplier:        1,
	IDCategoryDefault: 1,
	New:               1,
	//CacheDefaultAttribute: 1,
	//DefaultImage:         nil, //&prestashop.DefaultImage{},
	IDDefaultCombination: 1,
	IDTaxRulesGroup:      1,
	//PositionInCategory:   1,
	//ManufacturerName:      "",
	//Quantity:                0,
	Type:              "1",
	IDShopDefault:     1,
	Reference:         carbon.Now().ToShortDateTimeString(),
	SupplierReference: carbon.Now().ToShortDateTimeString(),
	//Location:                "",
	//Width:                   400,
	//Height:                  400,
	//Depth:                   1,
	//Weight:                  1,
	//QuantityDiscount:        "",
	Ean13: "1231231231231",
	//Isbn:                    "",
	//Upc:                     "",
	//Mpn:                     "",
	//CacheIsPack:             "",
	//CacheHasAttachments:     "",
	//IsVirtual:               "",
	State: 1,
	//AdditionalDeliveryTimes: 1,
	//DeliveryInStock:         &prestashop.LanguageData{},
	//DeliveryOutStock:        &prestashop.LanguageData{},
	ProductType: "standard",
	//OnSale:                  "",
	//OnlineOnly:              "",
	//Ecotax:                  1,
	//MinimalQuantity:         1,
	//LowStockThreshold:       1,
	//LowStockAlert:           "",
	Price: 123.45,
	//WholesalePrice:          1,
	//Unity:                   "",
	UnitPrice: 123.45,
	//UnitPriceRatio:          1,
	//AdditionalShippingCost:  1,
	//Customizable:            1,
	//TextFields:              1,
	//UploadableFiles:         1,
	Active: "1",
	//RedirectType:            "",
	//IDTypeRedirected:        0,
	//AvailableForOrder:       "",
	//AvailableDate:           "",
	//ShowCondition:           "",
	//Condition:               "",
	//ShowPrice:               "",
	//Indexed:                 "",
	//Visibility:              "",
	//AdvancedStockManagement: "",
	//DateAdd:                 "",
	//DateUpd:                 "",
	//PackStockType: 1,
	MetaDescription: BuildLanguageData(
		prestashop.Language{
			ID:    PrestashopLanguageZhCN,
			Value: "Meta 描述",
		},
		prestashop.Language{
			ID:    PrestashopLanguageUsEn,
			Value: "Meta Description",
		}),
	MetaKeywords: BuildLanguageData(
		prestashop.Language{
			ID:    PrestashopLanguageZhCN,
			Value: "Meta 关键字",
		},
		prestashop.Language{
			ID:    PrestashopLanguageUsEn,
			Value: "Meta Keywords",
		}),
	MetaTitle: BuildLanguageData(
		prestashop.Language{
			ID:    PrestashopLanguageZhCN,
			Value: "Meta 标题",
		},
		prestashop.Language{
			ID:    PrestashopLanguageUsEn,
			Value: "Meta Title",
		}),
	LinkRewrite: BuildLanguageData(
		prestashop.Language{
			ID:    PrestashopLanguageZhCN,
			Value: "awesome-product",
		},
		prestashop.Language{
			ID:    PrestashopLanguageUsEn,
			Value: "awesome-product",
		}),
	Names: BuildLanguageData(
		prestashop.Language{
			ID:    PrestashopLanguageZhCN,
			Value: "名称",
		},
		prestashop.Language{
			ID:    PrestashopLanguageUsEn,
			Value: "Name",
		}),
	Description: BuildLanguageData(
		prestashop.Language{
			ID:    PrestashopLanguageZhCN,
			Value: "描述",
		},
		prestashop.Language{
			ID:    PrestashopLanguageUsEn,
			Value: "Description",
		}),
	DescriptionShort: BuildLanguageData(
		prestashop.Language{
			ID:    PrestashopLanguageZhCN,
			Value: "简述",
		},
		prestashop.Language{
			ID:    PrestashopLanguageUsEn,
			Value: "Description Short",
		}),
	//AvailableNow:   nil,
	//AvailableLater: nil,
	//Associations:   nil,
}
product := PrestashopProductCreate(&data)

if product != nil {

}

}

func connect() *prestashop.Client {
client, err := prestashop.New(PrestashopUrl)
if err != nil {
slog.Error("prestashop", "err", err.Error())
return nil
}
client.Authenticate(Prestashopkey)

return client

}

func PrestashopProductCreate(product *prestashop.Product) *prestashop.Product {
client := connect()

data, _, err := client.Product.Create(product)

if err != nil {
	slog.Error("prestashop", "err", err.Error())
	return nil
}
dataJSON, _ := json.Marshal(*data)
slog.Info("prestashop", "product create", dataJSON)

if data != nil {
	slog.Info("prestashop", "product create", fmt.Sprintf("id: %d, name: %v", data.ID, &data.Names))
}

return data

}

I can get the created product result :)

2024/01/24 11:37:55 INFO prestashop product="id: 20, name: Name"

Please help change the ProductAssociations then I can do more.
type ProductAssociations struct {
ProductRows *[]ProductRow xml:"product_rows>cart_row,omitempty" json:"cart_rows,omitempty"
}






Thanks !

from go-prestashop-api.

nikkofu avatar nikkofu commented on September 27, 2024

closed,

I'm doing with xml+go-resty myself from scratch with original documents.

thanks for your company these days.

from go-prestashop-api.

dinistavares avatar dinistavares commented on September 27, 2024

Sorry I haven't been very active here, but would be interested to see your approach if you wouldnt mind sharing when you're done :)

from go-prestashop-api.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.