Insert Data Data in Database in the PDFService.cs

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
Hello everyone,

for the pdf-invoice, I create a QR-Code for every single product which was purchased.

Now I want to save the data(6 letters) behind the QR-code in the database.
I added a new Table in the Database. But I don't know how I can insert the data in the database.


How do I get the right context? Or what do I need to do that?

Can anyone help me?
3 years ago
Rather than create a new table, I think it would have better to either:
a) use a Product Specification Attribute
or
b) use GenericAttribute

If you don't ever need to see the value or manually edit it (in administration), then GenericAttribute is better.

In any case, the Product's Id would be the way to link the separate entities.
3 years ago
I just need to have access to the data with an API, wich will send the data to raspberry pi, but this is not the problem. I just need the 6 letters to be saved in the nop database so I have access to the data with the API

I hope there were no misunderstandings. Because if a user purchases  the same product twice, he will get two different QR-Codes for it. Because it will be used for the access controll



Would you be so nice to explain this a little bit to me?

I am a NopCommerce newbie, but I got little coding skills.

Or a example would be ok, too, so that I can understand what to do exactly.


Thanks in advance!
3 years ago
As New York said you can use the Generic Attribute table
Store a record for each OrderItem
E.g _genericAttributeService.SaveAttribute(...)

Otherwise if you want to use your own table see on of the other plugins which uses data
i.e Nop.Plugin.Tax.FixedOrByCountryStateZip
3 years ago
You can create a plugin to HandleEvent(OrderPaidEvent orderPaidEvent)
From OrderPaidEvent  you can get to Order
From Order.Id you can use OrderService to get the IList<OrderItem> GetOrderItems
Foreach OrderItem, create generic attribute

You'll note the the PDFService uses GetOrderItems:
var orderItems = _orderService.GetOrderItems(order.Id, vendorId: vendorId);
So you should be able to get the  generic attribute value to print your QR code.
3 years ago
So you think, I should create a new plugin to create and save the qr-code in the generic table.

Do you mean that?
3 years ago
Yes, that is what I recommend.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.