Perch Shop - Collection field to product

  • Hello,


    I am using Perch Shop and I have imported a lot of products. Now I would like to make a collection which I attach to a certain product, by using the same slug for the product and the collection item for example. I want to create a field in the collection which will be used as the price of the product, so this collection item field will overwrite the price of the product.


    What would be the best solution to achieve this?


    Mike




    EDIT:


    I tried overwriting the product price by setting the price variable, but no luck.


    Code
    1. $plantPrijs = perch_collection('Planten', [
    2. 'filter' => 'slug',
    3. 'match' => 'eq',
    4. 'value' => perch_get('s'),
    5. 'skip-template' => true,
    6. ]);
    7. $plantPrijs = $plantPrijs[0]['prijs'];
    8. PerchSystem::set_var('price', $plantPrijs);

    On the product page I am outputting the collection with the same slug. Retrieving the price field from the collection and trying to overwrite the original product price field with this value.

  • Hello,


    I want to create a field in the collection which will be used as the price of the product,


    Apart from displaying the Collection item's price instead of the Shop product's price on the product page, what are you trying to achieve? While you can output the Collection item's price on the product page, Perch Shop won't use that value in the cart or checkout.

  • Can you elaborate a little bit more about what you are trying to achieve? I may not be understanding correctly but it sounds like you’re looking for a product backup or versioning solution.


    The more details the better.

  • I use ProductImporter to get products from an API. I would like to change the price of the products.


    Currently there is no way to update products by using the ProductImporter. So to keep my products updated, I want to delete all products and import all products again from the API on a regular basis, so if a product is deleted or added in the API, it also gets deleted or added on my website.


    If I would just edit the price of a product, I would lose this value when deleting and importing back.


    So my idea was to create collections and connect them to products, by giving them the same slug for example. Use this collection to overwrite fields from the product.


    I hope this is not too vague of an explanation.

  • right no update through the product importer, but you could use the PerchShop_Products factory.


    As you loop through your api imported products, use the PerchShop_Products factory object to find the current product in the database, then you can update the price (or other fields) just before importing using the product importer.