<commit_before><?php

/**
 * This file is part of the hyyan/woo-poly-integration plugin.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Hyyan\WPI\Product;

use Hyyan\WPI\HooksInterface;
use Hyyan\WPI\Utilities;

/**
 * Variable
 *
 * Handle Variable Products
 *
 * @author Hyyan
 */
class Variable
{

    /**
     * Construct object
     */
    public function __construct()
    {

        add_action('save_post', array($this, 'variations'), 10, 3);

        // extend meta list to include variation meta
        add_filter(
                HooksInterface::PRODUCT_META_SYNC_FILTER
                , array($this, 'extendProductMetaList')
        );
    }

    /**
     * Translate Variation for given variable product
     *
     * @param integer  $ID     product variable ID
     * @param \WP_Post $post   Product Post
     * @param boolean  $update true if update , false otherwise
     *
     * @return boolean
     */
    public function variations($ID, \WP_Post $post, $update)
    {

        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return false;
        }

        global $pagenow;
        if (!in_array($pagenow, array('post.php', 'post-new.php'))) {
            return false;
        }

        $product = wc_get_product($ID);

        if (!$product) {
            return false;
        }

        $from = null;

        if (pll_get_post_language($ID) == pll_default_language()) {
            $from = $product;
        } else {

            if (isset($_GET['from_post'])) {
                /*
                 * This check will make sure that variation , will be
                 * created for brand new products which are not saved yet by user<commit_msg>Renamed method name from "variations" to "duplicate"<commit_after><?php

/**
 * This file is part of the hyyan/woo-poly-integration plugin.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Hyyan\WPI\Product;

use Hyyan\WPI\HooksInterface;
use Hyyan\WPI\Utilities;

/**
 * Variable
 *
 * Handle Variable Products
 *
 * @author Hyyan
 */
class Variable
{

    /**
     * Construct object
     */
    public function __construct()
    {

        add_action('save_post', array($this, 'duplicate'), 10, 3);

        // extend meta list to include variation meta
        add_filter(
                HooksInterface::PRODUCT_META_SYNC_FILTER
                , array($this, 'extendProductMetaList')
        );
    }

    /**
     * Translate Variation for given variable product
     *
     * @param integer  $ID     product variable ID
     * @param \WP_Post $post   Product Post
     * @param boolean  $update true if update , false otherwise
     *
     * @return boolean
     */
    public function duplicate($ID, \WP_Post $post, $update)
    {

        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return false;
        }

        global $pagenow;
        if (!in_array($pagenow, array('post.php', 'post-new.php'))) {
            return false;
        }

        $product = wc_get_product($ID);

        if (!$product) {
            return false;
        }

        $from = null;

        if (pll_get_post_language($ID) == pll_default_language()) {
            $from = $product;
        } else {

            if (isset($_GET['from_post'])) {
                /*
                 * This check will make sure that variation , will be
                 * created for brand new products which are not saved yet by user
{'fraction_non_alphanumeric': 0.1094391244870041, 'fraction_numerical': 0.0016415868673050615, 'mean_word_length': 2.01401483924155, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1667855', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1037, 'n_words': 303}