Plugin Directory

Changeset 2841766


Ignore:
Timestamp:
12/31/2022 10:30:55 AM (3 years ago)
Author:
aliparsa
Message:

bugfix: problem of get trashed products

Location:
pasazh/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pasazh/trunk/PASAZHAPIPasazhProduct.php

    r2840280 r2841766  
    2727    public $url;
    2828    public $commodity_id;
    29 //    public $guarantee;
     29
     30
    3031
    3132    /**
  • pasazh/trunk/pasazh.php

    r2840342 r2841766  
    66Plugin URI: https://epasazh.com
    77Description: با استفاده از این افزونه میتوانید فروشگاه خود را به پاساژ متصل نمایید. کافیست آن را فعال نمایید پس از آن به پنل مدیریت خودت در وب سایت پاساژ مراجعه نموده و ادامه مراحل جهت اتصال را تکمیل نمایید.
    8 Version: 1.7
     8Version: 1.8
    99Author: aliparsa
    1010Author URI: https://profiles.wordpress.org/aliparsa/
     
    3131});
    3232
    33 add_action('woocommerce_new_product', 'PASAZHAPI_sync_product', 10, 1);
    34 
    35 add_action('woocommerce_update_product', 'PASAZHAPI_sync_product', 10, 1);
    36 
    37 //region add two webhook for detect delete product
    38 add_action('before_delete_post', 'PASAZHAPI_sync_product');
     33//add_action('woocommerce_new_product', 'PASAZHAPI_sync_product', 10, 1);
     34//add_action('woocommerce_update_product', 'PASAZHAPI_sync_product', 10, 1);
     35add_action('deleted_post', 'PASAZHAPI_delete_product');
    3936add_action('save_post', 'PASAZHAPI_sync_product');
    40 //endregion
    41 
    42 
    43 //function wpse_110037_new_posts($post_id){
    44 //    $WC_Product = wc_get_product( $post_id);
    45 //
    46 //    if($WC_Product->status == "trash"){
    47 //
    48 //    }
    49 //}
     37
    5038
    5139//region api functions
     
    6654{
    6755
    68 
    6956    $base64 = $data->get_params()["query"];
    7057    $json = base64_decode($base64);
    7158    $query = json_decode($json, true);
     59    $query['status'] = [ 'trash', 'publish'];
     60//    $product_id = isset($query['include']) ? $query['include'][0] : null;
     61
     62
    7263
    7364    $pasazh_products = [];
    7465    $items = wc_get_products($query);
    75 
    7666    foreach ($items as $product) {
    7767        $pasazh_product = PASAZHAPI_get_pasazh_product_from_wc_product($product);
     
    7969    }
    8070
    81 
    8271    $response = [];
    8372    $response["meta"] = [
    84         "count" => sizeof($items)
     73        "count" => sizeof($pasazh_products)
    8574    ];
    8675    $response["products"] = $pasazh_products;
     
    9079}
    9180
    92 function PASAZHAPI_sync_product($product_id)
    93 {
     81function PASAZHAPI_delete_product($product_id)
     82{
     83
     84
    9485    try {
    9586        if (get_transient("papi_product_id") == $product_id) return;
    9687        set_transient('papi_product_id', $product_id, 1);
    9788
    98 
    99         $post_type = null;
    100 
    101         try {
    102             $query = [
    103                 "include" => [$product_id],
    104             ];
    105             $items = wc_get_products($query);
    106             $post_type = $items[0]->post_type;
    107         } catch (Exception $exception) {
    108 
    109         }
    110 
    111 
     89        $post = get_post($product_id);
     90
     91
     92        if (!$post)
     93            return;
     94
     95        $post_type = $post->post_type;
    11296        if ($post_type != "product")
     97            return;
     98
     99
     100        wp_remote_get("https://epasazh.com/api/webhooks/woocommerce/addon-product-deleted/$product_id", [
     101            "headers" => [
     102                "papi-source-url" => get_site_url()
     103            ]
     104        ]);
     105
     106
     107    } catch (Exception $e) {
     108
     109    }
     110
     111}
     112
     113function PASAZHAPI_sync_product($product_id)
     114{
     115
     116
     117    try {
     118        if (get_transient("papi_product_id") == $product_id) return;
     119        set_transient('papi_product_id', $product_id, 1);
     120
     121        $post = get_post($product_id);
     122
     123
     124        if (!$post)
     125            return;
     126
     127        $post_type = $post->post_type;
     128        if ($post_type != "product")
     129            return;
     130
     131
     132        if (in_array($post->post_status , ['auto-draft' , 'draft']) )
    113133            return;
    114134
     
    133153function PASAZHAPI_get_pasazh_product_from_wc_product($product)
    134154{
     155
     156    $product_status = $product->get_status();
    135157
    136158    $pasazh_product = new PASAZHAPIPasazhProduct();
  • pasazh/trunk/readme.txt

    r2840342 r2841766  
    55Requires at least: 5.0.3
    66Tested up to: 5.9.3
    7 Stable tag: 1.7
     7Stable tag: 1.8
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2323== Screenshots ==
    2424== Changelog ==
    25 = 1.7 =
     25= 1.8 =
    2626* First release
    2727== Upgrade Notice ==
Note: See TracChangeset for help on using the changeset viewer.