Plugin Directory

Changeset 2840313


Ignore:
Timestamp:
12/28/2022 09:13:28 AM (3 years ago)
Author:
aliparsa
Message:

roolback

Location:
pasazh/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pasazh/trunk/pasazh.php

    r2840280 r2840313  
    66Plugin URI: https://epasazh.com
    77Description: با استفاده از این افزونه میتوانید فروشگاه خود را به پاساژ متصل نمایید. کافیست آن را فعال نمایید پس از آن به پنل مدیریت خودت در وب سایت پاساژ مراجعه نموده و ادامه مراحل جهت اتصال را تکمیل نمایید.
    8 Version: 1.6
     8Version: 1.4
    99Author: aliparsa
    1010Author URI: https://profiles.wordpress.org/aliparsa/
     
    3535add_action('woocommerce_update_product', 'PASAZHAPI_sync_product', 10, 1);
    3636
    37 //region add two webhook for detect delete product
    38 add_action( 'before_delete_post', 'PASAZHAPI_sync_product' );
    39 add_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 //}
    50 
    5137//region api functions
    5238
     
    6652{
    6753
    68 
    6954    $base64 = $data->get_params()["query"];
    7055    $json = base64_decode($base64);
     
    7459    $items = wc_get_products($query);
    7560
    76 
    77 
    7861    foreach ($items as $product) {
    7962        $pasazh_product = PASAZHAPI_get_pasazh_product_from_wc_product($product);
    8063        $pasazh_products[] = $pasazh_product;
    8164    }
    82 
    8365
    8466    $response = [];
     
    9476function PASAZHAPI_sync_product($product_id)
    9577{
     78
    9679    try {
    9780        if (get_transient("papi_product_id") == $product_id) return;
    9881        set_transient('papi_product_id', $product_id, 1);
    99 
    10082        wp_remote_get("https://epasazh.com/api/webhooks/woocommerce/addon-product-updated/$product_id", [
    10183            "headers" => [
     
    10385            ]
    10486        ]);
    105 
    106 
    10787    } catch (Exception $e) {
    10888
     
    11797function PASAZHAPI_get_pasazh_product_from_wc_product($product)
    11898{
     99
    119100
    120101    $pasazh_product = new PASAZHAPIPasazhProduct();
    121102    $pasazh_product->setId($product->get_id());
    122103    $pasazh_product->setName($product->get_name());
     104    $pasazh_product->setDescription($product->get_description());
    123105    $pasazh_product->setUrl(get_permalink($product->get_id()));
    124 
    125     $description = $product->get_description();
    126     if (strlen($description) == 0) {
    127         foreach ($product->get_attributes() as $attribute) {
    128             $attribute_data = json_decode(json_encode($attribute['data'], JSON_PRETTY_PRINT));
    129             $is_visible = $attribute_data->is_visible == 1;
    130             if ($is_visible) {
    131                 $description .= $attribute_data->name . " : \r\n";
    132                 $description .= implode(' , ', $attribute_data->options);
    133                 $description .= "\r\n\r\n";
    134             }
    135         }
    136     }
    137 
    138     $pasazh_product->setDescription($description);
    139 
    140 
    141106
    142107    // region technical desc
    143108    $technical_description = "";
    144109    $attrs = $product->get_attributes();
    145 
    146     $test = "";
    147110    foreach ($attrs as $attr){
    148111
    149112        if ($attr["visible"] != true) continue;
    150113        if ($attr["variation"] == true) continue;
     114
    151115        if (strlen($technical_description)>0)
    152116            $technical_description .= "\n\n";
     
    155119        $options_text = "";
    156120        foreach ($data["options"] as $option){
    157 
    158121            if (strlen($options_text) > 0)
    159122                $options_text .=  " | " ;
    160123            $options_text .=  $option ;
    161124
    162             $test .= $options_text;
    163 
    164         }
    165 
     125        }
    166126        $technical_description .= $options_text ;
    167127    }
     
    177137        $specification_arr = [];
    178138
    179 
    180139        foreach ($product->get_available_variations() as $variation) {
    181 
    182             $is_in_stock = isset($variation['is_in_stock']) && $variation['is_in_stock'] == 1;
    183140
    184141            $specification_object = new \stdClass();
     
    189146            $specification_object->name = trim($specification_object->name);
    190147            $specification_object->price = $variation["display_price"];
    191             $specification_object->is_in_stock = $is_in_stock;
    192148            $specification_arr [] = $specification_object;
    193149
    194150        }
    195 
    196151
    197152        if (sizeof($specification_arr) > 0) {
  • pasazh/trunk/readme.txt

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