Use PerchShop_Products to find product using slug

  • Hello,


    Is it possible to use the PerchShop_Products to find a product using the slug or any other field, instead of searching for the ID like this example:


    Code
    1. $Products = new PerchShop_Products();
    2. $newProduct = $Products->find($product['id']);

    Can we use the ->find for looking for the slug?

  • You should be able to use

    Code
    1. $Products = new PerchShop_Products();
    2. $newProduct = $Products->get_one_by('productSlug', $product['slug']);

    You can check the PerchFactoryClass.php file, in the core folder, for a list of all available methods

  • It worked. I now used the SKU to check if the product already exists, if not I import the product.


    Code
    1. foreach($result['data'] as $productData){
    2. $Products = new PerchShop_Products();
    3. $newProduct = $Products->get_one_by('sku', $productData['productcode']);
    4. if (!$productData['productcode'] == $newProduct) {
    5.                 #
    6.             }
    7.         }