File "abstract-wc-legacy-product.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/includes/legacy/abstract-wc-legacy-product.php
File size: 16.11 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

if (!defined('ABSPATH')) {
    exit;
}
abstract class WC_Abstract_Legacy_Product extends WC_Data
{
    public function __isset($key)
    {
        $valid = array('id', 'product_attributes', 'visibility', 'sale_price_dates_from', 'sale_price_dates_to', 'post', 'download_type', 'product_image_gallery', 'variation_shipping_class', 'shipping_class', 'total_stock', 'crosssell_ids', 'parent');
        if ($this->is_type('variation')) {
            $valid = array_merge($valid, array('variation_id', 'variation_data', 'variation_has_stock', 'variation_shipping_class_id', 'variation_has_sku', 'variation_has_length', 'variation_has_width', 'variation_has_height', 'variation_has_weight', 'variation_has_tax_class', 'variation_has_downloadable_files'));
        }
        return in_array($key, array_merge($valid, array_keys($this->data))) || metadata_exists('post', $this->get_id(), '_' . $key) || metadata_exists('post', $this->get_parent_id(), '_' . $key);
    }
    public function __get($key)
    {
        if ('post_type' === $key) {
            return $this->post_type;
        }
        wc_doing_it_wrong($key, __('Product properties should not be accessed directly.', 'woocommerce'), '3.0');
        switch ($key) {
            case 'id':
                $value = $this->is_type('variation') ? $this->get_parent_id() : $this->get_id();
                break;
            case 'product_type':
                $value = $this->get_type();
                break;
            case 'product_attributes':
                $value = isset($this->data['attributes']) ? $this->data['attributes'] : '';
                break;
            case 'visibility':
                $value = $this->get_catalog_visibility();
                break;
            case 'sale_price_dates_from':
                return $this->get_date_on_sale_from() ? $this->get_date_on_sale_from()->getTimestamp() : '';
                break;
            case 'sale_price_dates_to':
                return $this->get_date_on_sale_to() ? $this->get_date_on_sale_to()->getTimestamp() : '';
                break;
            case 'post':
                $value = get_post($this->get_id());
                break;
            case 'download_type':
                return 'standard';
                break;
            case 'product_image_gallery':
                $value = $this->get_gallery_image_ids();
                break;
            case 'variation_shipping_class':
            case 'shipping_class':
                $value = $this->get_shipping_class();
                break;
            case 'total_stock':
                $value = $this->get_total_stock();
                break;
            case 'downloadable':
            case 'virtual':
            case 'manage_stock':
            case 'featured':
            case 'sold_individually':
                $value = $this->{"get_{$key}"}() ? 'yes' : 'no';
                break;
            case 'crosssell_ids':
                $value = $this->get_cross_sell_ids();
                break;
            case 'upsell_ids':
                $value = $this->get_upsell_ids();
                break;
            case 'parent':
                $value = wc_get_product($this->get_parent_id());
                break;
            case 'variation_id':
                $value = $this->is_type('variation') ? $this->get_id() : '';
                break;
            case 'variation_data':
                $value = $this->is_type('variation') ? wc_get_product_variation_attributes($this->get_id()) : '';
                break;
            case 'variation_has_stock':
                $value = $this->is_type('variation') ? $this->managing_stock() : '';
                break;
            case 'variation_shipping_class_id':
                $value = $this->is_type('variation') ? $this->get_shipping_class_id() : '';
                break;
            case 'variation_has_sku':
            case 'variation_has_length':
            case 'variation_has_width':
            case 'variation_has_height':
            case 'variation_has_weight':
            case 'variation_has_tax_class':
            case 'variation_has_downloadable_files':
                $value = true;
                break;
            default:
                if (in_array($key, array_keys($this->data))) {
                    $value = $this->{"get_{$key}"}();
                } else {
                    $value = get_post_meta($this->id, '_' . $key, true);
                }
                break;
        }
        return $value;
    }
    public function get_variation_default_attributes()
    {
        wc_deprecated_function('WC_Product_Variable::get_variation_default_attributes', '3.0', 'WC_Product::get_default_attributes');
        return apply_filters('woocommerce_product_default_attributes', $this->get_default_attributes(), $this);
    }
    public function get_gallery_attachment_ids()
    {
        wc_deprecated_function('WC_Product::get_gallery_attachment_ids', '3.0', 'WC_Product::get_gallery_image_ids');
        return $this->get_gallery_image_ids();
    }
    public function set_stock($amount = null, $mode = 'set')
    {
        wc_deprecated_function('WC_Product::set_stock', '3.0', 'wc_update_product_stock');
        return wc_update_product_stock($this, $amount, $mode);
    }
    public function reduce_stock($amount = 1)
    {
        wc_deprecated_function('WC_Product::reduce_stock', '3.0', 'wc_update_product_stock');
        return wc_update_product_stock($this, $amount, 'decrease');
    }
    public function increase_stock($amount = 1)
    {
        wc_deprecated_function('WC_Product::increase_stock', '3.0', 'wc_update_product_stock');
        return wc_update_product_stock($this, $amount, 'increase');
    }
    public function check_stock_status()
    {
        wc_deprecated_function('WC_Product::check_stock_status', '3.0');
    }
    public function get_related($limit = 5)
    {
        wc_deprecated_function('WC_Product::get_related', '3.0', 'wc_get_related_products');
        return wc_get_related_products($this->get_id(), $limit);
    }
    protected function get_related_terms($term)
    {
        wc_deprecated_function('WC_Product::get_related_terms', '3.0', 'wc_get_product_term_ids');
        return array_merge(array(0), wc_get_product_term_ids($this->get_id(), $term));
    }
    protected function build_related_query($cats_array, $tags_array, $exclude_ids, $limit)
    {
        wc_deprecated_function('WC_Product::build_related_query', '3.0', 'Product Data Store get_related_products_query');
        $data_store = WC_Data_Store::load('product');
        return $data_store->get_related_products_query($cats_array, $tags_array, $exclude_ids, $limit);
    }
    public function get_child($child_id)
    {
        wc_deprecated_function('WC_Product::get_child', '3.0', 'wc_get_product');
        return wc_get_product($child_id);
    }
    public function get_price_html_from_text()
    {
        wc_deprecated_function('WC_Product::get_price_html_from_text', '3.0', 'wc_get_price_html_from_text');
        return wc_get_price_html_from_text();
    }
    public function get_price_html_from_to($from, $to)
    {
        wc_deprecated_function('WC_Product::get_price_html_from_to', '3.0', 'wc_format_sale_price');
        return apply_filters('woocommerce_get_price_html_from_to', wc_format_sale_price($from, $to), $from, $to, $this);
    }
    public function list_attributes()
    {
        wc_deprecated_function('WC_Product::list_attributes', '3.0', 'wc_display_product_attributes');
        wc_display_product_attributes($this);
    }
    public function get_price_including_tax($qty = 1, $price = '')
    {
        wc_deprecated_function('WC_Product::get_price_including_tax', '3.0', 'wc_get_price_including_tax');
        return wc_get_price_including_tax($this, array('qty' => $qty, 'price' => $price));
    }
    public function get_display_price($price = '', $qty = 1)
    {
        wc_deprecated_function('WC_Product::get_display_price', '3.0', 'wc_get_price_to_display');
        return wc_get_price_to_display($this, array('qty' => $qty, 'price' => $price));
    }
    public function get_price_excluding_tax($qty = 1, $price = '')
    {
        wc_deprecated_function('WC_Product::get_price_excluding_tax', '3.0', 'wc_get_price_excluding_tax');
        return wc_get_price_excluding_tax($this, array('qty' => $qty, 'price' => $price));
    }
    public function adjust_price($price)
    {
        wc_deprecated_function('WC_Product::adjust_price', '3.0', 'WC_Product::set_price / WC_Product::get_price');
        $this->data['price'] = $this->data['price'] + $price;
    }
    public function get_categories($sep = ', ', $before = '', $after = '')
    {
        wc_deprecated_function('WC_Product::get_categories', '3.0', 'wc_get_product_category_list');
        return wc_get_product_category_list($this->get_id(), $sep, $before, $after);
    }
    public function get_tags($sep = ', ', $before = '', $after = '')
    {
        wc_deprecated_function('WC_Product::get_tags', '3.0', 'wc_get_product_tag_list');
        return wc_get_product_tag_list($this->get_id(), $sep, $before, $after);
    }
    public function get_post_data()
    {
        wc_deprecated_function('WC_Product::get_post_data', '3.0', 'get_post');
        if ($this->is_type('variation')) {
            $post_data = get_post($this->get_parent_id());
        } else {
            $post_data = get_post($this->get_id());
        }
        return $post_data;
    }
    public function get_parent()
    {
        wc_deprecated_function('WC_Product::get_parent', '3.0', 'WC_Product::get_parent_id');
        return apply_filters('woocommerce_product_parent', absint($this->get_post_data()->post_parent), $this);
    }
    public function get_upsells()
    {
        wc_deprecated_function('WC_Product::get_upsells', '3.0', 'WC_Product::get_upsell_ids');
        return apply_filters('woocommerce_product_upsell_ids', $this->get_upsell_ids(), $this);
    }
    public function get_cross_sells()
    {
        wc_deprecated_function('WC_Product::get_cross_sells', '3.0', 'WC_Product::get_cross_sell_ids');
        return apply_filters('woocommerce_product_crosssell_ids', $this->get_cross_sell_ids(), $this);
    }
    public function has_default_attributes()
    {
        wc_deprecated_function('WC_Product_Variable::has_default_attributes', '3.0', 'a check against WC_Product::get_default_attributes directly');
        if (!$this->get_default_attributes()) {
            return true;
        }
        return false;
    }
    public function get_variation_id()
    {
        wc_deprecated_function('WC_Product::get_variation_id', '3.0', 'WC_Product::get_id(). It will always be the variation ID if this is a variation.');
        return $this->get_id();
    }
    public function get_variation_description()
    {
        wc_deprecated_function('WC_Product::get_variation_description', '3.0', 'WC_Product::get_description()');
        return $this->get_description();
    }
    public function has_all_attributes_set()
    {
        wc_deprecated_function('WC_Product::has_all_attributes_set', '3.0', 'an array filter on get_variation_attributes for a quick solution.');
        $set = true;
        foreach ($this->get_variation_attributes() as $att) {
            if (!$att) {
                $set = false;
                break;
            }
        }
        return $set;
    }
    public function parent_is_visible()
    {
        wc_deprecated_function('WC_Product::parent_is_visible', '3.0');
        return $this->is_visible();
    }
    public function get_total_stock()
    {
        wc_deprecated_function('WC_Product::get_total_stock', '3.0', 'get_stock_quantity on each child. Beware of performance issues in doing so.');
        if (sizeof($this->get_children()) > 0) {
            $total_stock = max(0, $this->get_stock_quantity());
            foreach ($this->get_children() as $child_id) {
                if ('yes' === get_post_meta($child_id, '_manage_stock', true)) {
                    $stock = get_post_meta($child_id, '_stock', true);
                    $total_stock += max(0, wc_stock_amount($stock));
                }
            }
        } else {
            $total_stock = $this->get_stock_quantity();
        }
        return wc_stock_amount($total_stock);
    }
    public function get_formatted_variation_attributes($flat = false)
    {
        wc_deprecated_function('WC_Product::get_formatted_variation_attributes', '3.0', 'wc_get_formatted_variation');
        return wc_get_formatted_variation($this, $flat);
    }
    public function variable_product_sync($product_id = 0)
    {
        wc_deprecated_function('WC_Product::variable_product_sync', '3.0');
        if (empty($product_id)) {
            $product_id = $this->get_id();
        }
        if (is_callable(array(__CLASS__, 'sync'))) {
            self::sync($product_id);
        }
    }
    public static function sync_attributes($product, $children = false)
    {
        if (!is_a($product, 'WC_Product')) {
            $product = wc_get_product($product);
        }
        if (version_compare(get_post_meta($product->get_id(), '_product_version', true), '2.4.0', '<')) {
            $parent_attributes = array_filter((array) get_post_meta($product->get_id(), '_product_attributes', true));
            if (!$children) {
                $children = $product->get_children('edit');
            }
            foreach ($children as $child_id) {
                $all_meta = get_post_meta($child_id);
                foreach ($all_meta as $name => $value) {
                    if (0 !== strpos($name, 'attribute_')) {
                        continue;
                    }
                    if (sanitize_title($value[0]) === $value[0]) {
                        foreach ($parent_attributes as $attribute) {
                            if ('attribute_' . sanitize_title($attribute['name']) !== $name) {
                                continue;
                            }
                            $text_attributes = wc_get_text_attributes($attribute['value']);
                            foreach ($text_attributes as $text_attribute) {
                                if (sanitize_title($text_attribute) === $value[0]) {
                                    update_post_meta($child_id, $name, $text_attribute);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    public function get_matching_variation($match_attributes = array())
    {
        wc_deprecated_function('WC_Product::get_matching_variation', '3.0', 'Product data store find_matching_product_variation');
        $data_store = WC_Data_Store::load('product');
        return $data_store->find_matching_product_variation($this, $match_attributes);
    }
    public function enable_dimensions_display()
    {
        wc_deprecated_function('WC_Product::enable_dimensions_display', '3.0');
        return apply_filters('wc_product_enable_dimensions_display', true) && ($this->has_dimensions() || $this->has_weight() || $this->child_has_weight() || $this->child_has_dimensions());
    }
    public function get_rating_html($rating = null)
    {
        wc_deprecated_function('WC_Product::get_rating_html', '3.0', 'wc_get_rating_html');
        return wc_get_rating_html($rating);
    }
    public static function sync_average_rating($post_id)
    {
        wc_deprecated_function('WC_Product::sync_average_rating', '3.0', 'WC_Comments::get_average_rating_for_product or leave to CRUD.');
        self::sync_rating_count($post_id);
        $average = WC_Comments::get_average_rating_for_product(wc_get_product($post_id));
        update_post_meta($post_id, '_wc_average_rating', $average);
    }
    public static function sync_rating_count($post_id)
    {
        wc_deprecated_function('WC_Product::sync_rating_count', '3.0', 'WC_Comments::get_rating_counts_for_product or leave to CRUD.');
        $counts = WC_Comments::get_rating_counts_for_product(wc_get_product($post_id));
        update_post_meta($post_id, '_wc_rating_count', $counts);
    }
    public function get_files()
    {
        wc_deprecated_function('WC_Product::get_files', '3.0', 'WC_Product::get_downloads');
        return $this->get_downloads();
    }
    public function grouped_product_sync()
    {
        wc_deprecated_function('WC_Product::grouped_product_sync', '3.0');
    }
}