Plugin Directory

Changeset 2835362


Ignore:
Timestamp:
12/17/2022 05:19:27 AM (3 years ago)
Author:
aliparsa
Message:

bugfix:problem of get description from products that dont have raw description

Location:
pasazh/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pasazh/trunk/pasazh.php

    r2764016 r2835362  
    66Plugin URI: https://epasazh.com
    77Description: با استفاده از این افزونه میتوانید فروشگاه خود را به پاساژ متصل نمایید. کافیست آن را فعال نمایید پس از آن به پنل مدیریت خودت در وب سایت پاساژ مراجعه نموده و ادامه مراحل جهت اتصال را تکمیل نمایید.
    8 Version: 1.4
     8Version: 1.5
    99Author: aliparsa
    1010Author URI: https://profiles.wordpress.org/aliparsa/
     
    1515*/
    1616
    17 const PASAZHAPI_papi_version = "1.0";
     17const PASAZHAPI_papi_version = "1.5";
    1818
    1919add_action('rest_api_init', function () {
     
    6969    ];
    7070    $response["products"] = $pasazh_products;
    71 
    7271
    7372    return new WP_REST_Response($response, 200);
     
    102101    $pasazh_product->setId($product->get_id());
    103102    $pasazh_product->setName($product->get_name());
    104     $pasazh_product->setDescription($product->get_description());
    105103    $pasazh_product->setUrl(get_permalink($product->get_id()));
     104
     105
     106    $description = $product->get_description();
     107
     108    //get description from variations
     109    if (strlen($description) == 0) {
     110
     111            foreach ($product->get_attributes() as $attribute) {
     112                $attribute_data = json_decode(json_encode($attribute['data'], JSON_PRETTY_PRINT));
     113                $is_visible = $attribute_data->is_visible == 1;
     114                if ($is_visible) {
     115                    $description .= $attribute_data->name . " : \r\n";
     116                    $description .= implode(',', $attribute_data->options);
     117                    $description .= "\r\n\r\n";
     118                }
     119            }
     120
     121    }
     122    $pasazh_product->setDescription($description);
     123
    106124
    107125    // region technical desc
    108126    $technical_description = "";
    109127    $attrs = $product->get_attributes();
    110     foreach ($attrs as $attr){
     128    foreach ($attrs as $attr) {
    111129
    112130        if ($attr["visible"] != true) continue;
    113131        if ($attr["variation"] == true) continue;
    114132
    115         if (strlen($technical_description)>0)
     133        if (strlen($technical_description) > 0)
    116134            $technical_description .= "\n\n";
    117135        $data = $attr->get_data();
    118136        $technical_description .= $data["name"] . " : \n";
    119137        $options_text = "";
    120         foreach ($data["options"] as $option){
     138        foreach ($data["options"] as $option) {
    121139            if (strlen($options_text) > 0)
    122                 $options_text .=  " | " ;
    123             $options_text .=  $option ;
    124 
    125         }
    126         $technical_description .= $options_text ;
     140                $options_text .= " | ";
     141            $options_text .= $option;
     142
     143        }
     144        $technical_description .= $options_text;
    127145    }
    128146
     
    161179        $quantity = $product->get_stock_quantity();
    162180    } else {
    163         if($product->is_in_stock()){
     181        if ($product->is_in_stock()) {
    164182            $quantity = 1;
    165183        }
  • pasazh/trunk/readme.txt

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