<commit_before><?php
/**
 * This file is part of SplashSync Project.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 *  @author    Splash Sync <www.splashsync.com>
 *  @copyright 2015-2017 Splash Sync
 *  @license   GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
 *
 **/

namespace Splash\Local\Objects\Product;

use Splash\Core\SplashCore      as Splash;

/**
 * Wordpress Page, Post, Product CRUD Functions
 */
trait CRUDTrait
{
    use \Splash\Local\Objects\Post\CRUDTrait;                   // Objects CRUD
    
    /**
     * @abstract    Load Request Object
     *
     * @param       int   $Id               Object id
     *
     * @return      mixed
     */
    public function load($Id)
    {
        //====================================================================//
        // Stack Trace
        Splash::log()->trace(__CLASS__, __FUNCTION__);
        //====================================================================//
        // Init Object
        $Post           =       get_post($Id);
        //====================================================================//
        // Load WooCommerce Product Object
        $Product        =       wc_get_product($Id);
        if ($Product) {
            $this->Product  =       $Product;
        }
        if (is_wp_error($Post)) {
            return Splash::log()->err(
                "ErrLocalTpl",
                __CLASS__,
                __FUNCTION__,
                " Unable to load " . self::$NAME . " (" . $Id . ")."
            );
        }
        //====================================================================//
        // Load WooCommerce Parent Product Object
        $this->loadParent();
        return $Post;
    }
    
    /**
     * @abstract    Create a New Product Variation
     * @return      object|false
     */
    public function create()
    {
        //====================================================================//
        // Check is New Product is Variant Product
        if (!isset($this->In["attributes"]) || empty($this->In["attributes"])) {
            $this->In["post_title"] =       $this->In["base_title"];
            return $this->createPost();
        }
        //====================================================================//
        // Check Required Fields
        if (empty($this->In["base_title"])) {
            return Splash::log()->err("ErrLocalFieldMissing", __CLASS__, __FUNCTION__, "base_title");<commit_msg>Wip : WP Multilang & Product variations<commit_after><?php
/**
 * This file is part of SplashSync Project.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 *  @author    Splash Sync <www.splashsync.com>
 *  @copyright 2015-2017 Splash Sync
 *  @license   GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
 *
 **/

namespace Splash\Local\Objects\Product;

use Splash\Core\SplashCore      as Splash;

/**
 * Wordpress Page, Post, Product CRUD Functions
 */
trait CRUDTrait
{
    use \Splash\Local\Objects\Post\CRUDTrait;                   // Objects CRUD
    
    /**
     * @abstract    Load Request Object
     *
     * @param       int   $Id               Object id
     *
     * @return      mixed
     */
    public function load($Id)
    {
        //====================================================================//
        // Stack Trace
        Splash::log()->trace(__CLASS__, __FUNCTION__);
        //====================================================================//
        // Init Object
        $Post           =       get_post($Id);
        //====================================================================//
        // Load WooCommerce Product Object
        $Product        =       wc_get_product($Id);
        if ($Product) {
            $this->Product  =       $Product;
        }
        if (is_wp_error($Post)) {
            return Splash::log()->err(
                "ErrLocalTpl",
                __CLASS__,
                __FUNCTION__,
                " Unable to load " . self::$NAME . " (" . $Id . ")."
            );
        }
        //====================================================================//
        // Load WooCommerce Parent Product Object
        $this->loadParent();
        return $Post;
    }
    
    /**
     * @abstract    Create a New Product Variation
     * @return      object|false
     */
    public function create()
    {
        //====================================================================//
        // Check is New Product is Variant Product
        if (!isset($this->In["attributes"]) || empty($this->In["attributes"])) {
            $this->In["post_title"] =       $this->In["base_title"];
var_dump($this->In);
            return $this->createPost();
        }
        //====================================================================//
        // Check Required Fields
        if (empty($this->In["base_title"])) {
            return Splash::log()->err("ErrLocalFieldMissing", __CLASS__, __FUNCTION__, "base_title");
{'fraction_non_alphanumeric': 0.2523076923076923, 'fraction_numerical': 0.005429864253393665, 'mean_word_length': 2.1631368059530622, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1863216', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1314, 'n_words': 362}