Generic Attribute Service XML - nop 4.30

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
Hi Everyone!

Question - how is the XML created for the Generic Attribute Service?

When I try and save a new attribute using my model, all that gets inserted is the model name.

eg.
_genericAttributeService.SaveAttribute(_workContext.CurrentCustomer, CustomNopCustomerDefaults.DPDShopToShopLocationId, dpdShipToShopLocation, _storeContext.CurrentStore.Id);

Results in the value being saved as: Nop.Plugin.Widgets.DPDShipToShop.Models.DPDShipToShopLocation

I've also tried my domain model too.

I can insert a single value, such as the ID:
_genericAttributeService.SaveAttribute(_workContext.CurrentCustomer, CustomNopCustomerDefaults.DPDShopToShopLocationId, dpdShipToShopLocation.Id, _storeContext.CurrentStore.Id);


This gets inserted fine.

At the moment, I'm making a call to the DB to a custom table to see if the value passed exists, if it does, I update it with the new values.

If the table doesn't contain anything, then I insert the passed values.

Then, I'll take the ID from that insert/check, and create the Generic Attribute. It would be much simpler, and faster if I could just store all the values that I want in the Generic Attribute Service.

My Model:

Id = shiptoshoplocation.Id.ToString(),
                ProviderSystemName = DPDShipToShopDefaults.SystemName,
                PickupLocationCode = shiptoshoplocation.PickupLocationCode,
                Organisation = shiptoshoplocation.Organisation,
                Property = shiptoshoplocation.Property,
                Street = shiptoshoplocation.Street,
                Locality = shiptoshoplocation.Locality,
                Town = shiptoshoplocation.Town,
                County = shiptoshoplocation.County,
                Postcode = shiptoshoplocation.Postcode,
                CountryCode = shiptoshoplocation.CountryCode,
                CustomerId = customer.Id,
                Latitude = shiptoshoplocation.Latitude,
                Longitude = shiptoshoplocation.Longitude,
                CreatedOnUtc = DateTime.UtcNow


Thanks in advance,
Craig
3 years ago
You need to specify the Type (i.e. use the 'generic method')

The 'SelectedPickupPoint' is such an example:

_genericAttributeService.SaveAttribute<PickupPoint>(customer, NopCustomerDefaults.SelectedPickupPointAttribute, null, storeId);

...
var selectedPickupPoint = _genericAttributeService.GetAttribute<PickupPoint>(customer, NopCustomerDefaults.SelectedPickupPointAttribute, _storeContext.CurrentStore.Id);
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.