Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2006
    Posts
    919
    Plugin Contributions
    2

    Default Automatically delete products...

    My suppliers provide me with 'discontinued items' xml feeds. While I have already intergrated a live stock status feed into my website, I would like to do the same for discontinued products.

    So, I would like the discontinued products and their images to be automatically deleted.

    I can easily extract the information from my suppliers xml file, but how would I delete the products (and their images) from my store database?

    I understand that when you delete a product from the admin it's not the same end result as simply removing that product record from the database.

    Can anyone advise me on this please? Thanks in advance. :)

  2. #2
    Join Date
    Nov 2005
    Location
    Netherlands
    Posts
    53
    Plugin Contributions
    0

    Default Re: Automatically delete products...

    Have used in the past easypopulate with v_status=9 in order to delete the product items. Not sure about the images
    zensational

  3. #3
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Automatically delete products...

    Quote Originally Posted by Alex Clarke View Post
    I understand that when you delete a product from the admin it's not the same end result as simply removing that product record from the database.
    Correct - there is a lot of other cleanup done, including unlinking from cross-linked categories, and more.
    The code used to do deletes of non-customized-product-type products can be seen in /admin/includes/modules/delete_product_confirm.php
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  4. #4
    Join Date
    Mar 2006
    Posts
    919
    Plugin Contributions
    2

    Default Re: Automatically delete products...

    Quote Originally Posted by Rik View Post
    Have used in the past easypopulate with v_status=9 in order to delete the product items. Not sure about the images
    I didn't know about that. Probably won't use it as DrByte has pointed me in the right direction again (see below). Thanks for replying anyway. :)

    Quote Originally Posted by DrByte View Post
    Correct - there is a lot of other cleanup done, including unlinking from cross-linked categories, and more.
    The code used to do deletes of non-customized-product-type products can be seen in /admin/includes/modules/delete_product_confirm.php
    Excellent, thanks for that. I'll have a look at the code tomorrow and see what I can come up with.

  5. #5
    Join Date
    Mar 2006
    Posts
    919
    Plugin Contributions
    2

    Default Re: Automatically delete products...

    I've had a quick look at the code. Is it correct that I should only need to use the following?

    Code:
        // remove product from all its categories:
        for ($k=0, $m=sizeof($product_categories); $k<$m; $k++) {
          $db->Execute("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . "
                        where products_id = '" . (int)$product_id . "'
                        and categories_id = '" . (int)$product_categories[$k] . "'");
        }
        // confirm that product is no longer linked to any categories
        $count_categories = $db->Execute("select count(categories_id) as total
                                          from " . TABLE_PRODUCTS_TO_CATEGORIES . "
                                          where products_id = '" . (int)$product_id . "'");
        // echo 'count of category links for this product=' . $count_categories->fields['total'] . '<br />';
    
        // if not linked to any categories, do delete:
        if ($count_categories->fields['total'] == '0') {
          zen_remove_product($product_id, $delete_linked);
        }

  6. #6
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Automatically delete products...

    Without looking at the file again to confirm, I think that's about right.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. Replies: 0
    Last Post: 5 Feb 2013, 10:08 AM
  2. v150 How to delete manually installed 1.3.8a and automatically install 1.5.0?
    By zenartman in forum Upgrading to 1.5.x
    Replies: 2
    Last Post: 21 Feb 2012, 12:35 AM
  3. Replies: 13
    Last Post: 3 Oct 2011, 02:22 PM
  4. Automatically dispatch certain products?
    By HManney in forum Managing Customers and Orders
    Replies: 0
    Last Post: 26 Jul 2011, 09:23 PM
  5. Can't delete products in cart with delete button
    By DaveS in forum General Questions
    Replies: 4
    Last Post: 20 Sep 2009, 09:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg