Trying to get product from picture

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
I'm trying to work my way from picture to product via productpicture. The problem I see is that the relationship from productpicture to picture is not a 1to1 but a *to1. Could a picture ever be linked to multiple productpictures?
13 年 前
bhiers wrote:
I'm trying to work my way from picture to product via productpicture. The problem I see is that the relationship from productpicture to picture is not a 1to1 but a *to1. Could a picture ever be linked to multiple productpictures?

What problem are you having accessing a Product from a ProductPicture? The ProductPicture class has properties for PictureId and ProductId.  

The table Nop_ProductPicture works as a junction table so just as a product can have multiple pictures, a picture can have multiple products. Therefore, both Nop_Picture and Nop_Product relate to Nop_ProductPicture as one-to-many (Nop_Picture and Nop_Product are essentially related as many-to-many through this table). You would have to manually update the table and reuse a picture id to have a picture used for multiple products as there is no interface in nopCommerce to select an existing (in Nop_Picture) picture for a product.

.
13 年 前
I understand that, but the way the system is current setup I don't see how an picture would have multiple productpictures linked to it.. Right now its a single product can have multiple productpictures and each productpicture has a picture. But the link between picture and productpictures returns a collection.

Picture.NpProductPictures returns a collection of 1 ;-)

Should the productpicture.pictureid be unique and the link between pictures and productpicture be a 1to1 and then the link from productpicture to product be * to 1 ?
13 年 前
bhiers wrote:
I understand that, but the way the system is current setup I don't see how an picture would have multiple productpictures linked to it.. Right now its a single product can have multiple productpictures and each productpicture has a picture. But the link between picture and productpictures returns a collection.

Picture.NpProductPictures returns a collection of 1 ;-)

Should the productpicture.pictureid be unique and the link between pictures and productpicture be a 1to1 and then the link from productpicture to product be * to 1 ?

Right, there is a way to insert multiple picture IDs for a single product ID (via inserting pictures for a product), but there is no way to insert multiple products (IDs) to use a single picture (ID) through nopCommerce UI, nor does there need to be -in my opinion.

Picture.NpProductPictures is a collection because it represents the many in the one-to-many relationship between the Nop_Picture and Nop_ProductPicture tables. In your original post, you said you had a problem accessing a product via the ProductPicture. Are you having difficulty accessing the productID in the collection or are you trying to change the collection to a single ProductPicture variable and implement a one-to-one relationship between Nop_Picture and Nop_ProductPicture?

.
13 年 前
No I figured it out I just get the collect and then do a .first .. just seems silly to have to do so.. think its something that should be corrected..
13 年 前
you can modify the code to allow pictures "copy" from one product to another, or build a new ASCX in media manager to allow this picture 'shared' in product A,B,C,D,E.... anyway i think this requirement is necessary for some shops :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.