Creation of wp products

parent 4d3cd6ec
......@@ -9,6 +9,7 @@ based on the ideas I planned for www.sexhack.me:
- Version 0.0.3:
* Integration of Ultimate Members plugin for user and model profiles
* 404 Not Found page with gallery instead of WC products
- Version 0.0.4:
* Upload Videos page for models
......
......@@ -92,7 +92,6 @@ if(!class_exists('SH_GDrive')) {
} else {
$gdo = $igd->get_files(array('q'=> "name='{$part}"), $parent, false);
}
sexhack_log($gdo);
if(!is_array($gdo) || (count($gdo) < 1) || array_key_exists('error', $gdo)) break;
$parent=false;
......
......@@ -48,7 +48,7 @@ if(!class_exists('SH_MetaBox')) {
add_meta_box('video_tags', 'Video tags', 'wp_SexHackMe\SH_MetaBox::video_tags_meta_box', 'sexhack_video', 'side', 'default');
// Re-add featured image thumbnail
add_meta_box('video_postimagediv', 'Video Thumbnail', 'post_thumbnail_meta_box', 'sexhack_video', 'side', 'default');
add_meta_box('postimagediv', 'Video Thumbnail', 'post_thumbnail_meta_box', 'sexhack_video', 'side', 'default');
// XXX Remove Paid Member Subscription meta boxes
remove_meta_box( 'pms_post_content_restriction', 'sexhack_video', 'normal');
......
......@@ -52,6 +52,8 @@ if(!class_exists('SH_Query')) {
if(is_object($video))
{
$video = apply_filters('video_before_save', $video);
//sexhack_log($video);
$fieldsarrayraw = $video->get_sql_array();
$fieldsarray = array();
......
......@@ -78,7 +78,7 @@ if(!class_exists('SH_Video')) {
'views_public' => 0,
'views_members' => 0,
'views_premium' => 0,
'sells' => 0
'sales' => 0
);
public function __construct($attr=false)
{
......
......@@ -31,7 +31,8 @@ if(!class_exists("SH_VideoProducts")) {
public function __construct()
{
add_action('sh_save_video_after_query', array($this, 'sync_product_from_video'), 1, 10);
//add_action('sh_save_video_after_query', array($this, 'sync_product_from_video'), 1, 10);
add_filter('video_before_save', array($this, 'sync_product_from_video'));
}
public function sync_product_from_video($video)
......@@ -39,10 +40,103 @@ if(!class_exists("SH_VideoProducts")) {
sexhack_log("PRODUUUUUUCT");
sexhack_log($video);
$download = apply_filters('sh_download_url_filter', $video->download_public);
sexhack_log($download);
$prod = false;
// Get product if already set in video
if(intval($video->product_id) > 0)
$prod = wc_get_product($video->product_id);
// Create a new one if not present
if(!$prod) {
$prod = new \WC_Product_Simple();
}
// main product settings
$prod->set_name($video->title);
$prod->set_slug($video->slug); // XXX TODO Compose slug with username too to avoid name collisions?
// Product description.
$video_link=site_url().'/'.get_option('gallery_slug', 'v')."/"; // XXX TODO Get the right product link
$prod->set_short_description('<p>Whach me <a href="'.$video_link.'">ONLINE HERE</a></p>');
$prod->set_description($video->description);
// Product image: XXX TODO and if it isn't numeric?
if(is_numeric($video->thumbnail))
$prod->set_image_id( intval($video->thumbnail ));
// Product status.
if($video->status == 'published')
$prod->set_status('published');
else
$prod->set_status('draft');
// Not visible in catalog
$prod->set_catalog_visibility('hidden');
// Set the product as virtual and downloadable
$prod->set_virtual(true);
$prod->set_downloadable(true);
// Price
$prod->set_regular_price(floatval($video->price));
// Prepare product attributes
$attrs = array();
// Videw Preview
$attribute = new \WC_Product_Attribute();
$attribute->set_name( 'video_preview' );
$attribute->set_options( array($video->preview) );
$attribute->set_visible( false );
$attribute->set_variation( false );
$attrs[] = $attribute;
$prod->set_attributes($attrs);
// Download links
$download_public = apply_filters('sh_download_url_filter', $video->download_public);
$download_members = apply_filters('sh_download_url_filter', $video->download_members);
$download_premium = apply_filters('sh_download_url_filter', $video->download_premium);
$wcdowns = array();
if($download_public)
{
$wcdownload = new \WC_Product_Download();
$wcdownload->set_name(basename($video->download_public)); // XXX Do we really want to use basename here?
$wcdownload->set_id( md5( $download_public ));
$wcdownload->set_file( $download_public );
$wcdowns[] = $wcdownload;
}
if($download_members)
{
$wcdownload = new \WC_Product_Download();
$wcdownload->set_name(basename($video->download_members)); // XXX Do we really want to use basename here?
$wcdownload->set_id( md5( $download_members ));
$wcdownload->set_file( $download_members );
$wcdowns[] = $wcdownload;
}
if($download_premium)
{
$wcdownload = new \WC_Product_Download();
$wcdownload->set_name(basename($video->download_premium)); // XXX Do we really want to use basename here?
$wcdownload->set_id( md5( $download_premium ));
$wcdownload->set_file( $download_premium );
$wcdowns[] = $wcdownload;
}
$prod->set_downloads( $wcdowns );
$prod->save();
$video->product_id = $prod->get_id();
//sexhack_log($video);
return $video;
}
}
......
......@@ -33,6 +33,14 @@ function save_sexhack_video_meta_box_data( $post_id )
return;
}
// We need to be executed only when post_type is set...
if(!isset($_POST['post_type'])) return;
// ... ant it's set to sexhack_video
if($_POST['post_type']!='sexhack_video') return;
// Make sure we don't get caught in any loop
unset($_POST['sh_video_description_nonce']);
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
......
......@@ -211,7 +211,7 @@ if(!class_exists('SexHackMe_Plugin')) {
views_public bigint(32) NOT NULL DEFAULT '0',
views_members bigint(32) NOT NULL DEFAULT '0',
views_premium bigint(32) NOT NULL DEFAULT '0',
sells bigint(32) NOT NULL DEFAULT '0',
sales bigint(32) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
KEY user_id (user_id),
KEY post_id (post_id),
......@@ -649,8 +649,8 @@ if(!class_exists('SexHackMe_Plugin')) {
if( WP_DEBUG === true ){
// only matched?
//add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules');
//sexhack_log("REQUEST: ".$_SERVER['REQUEST_URI']." QUERY: ".$_SERVER['QUERY_STRING']. "POST:");
//sexhack_log($_POST);
sexhack_log("REQUEST: ".$_SERVER['REQUEST_URI']." QUERY: ".$_SERVER['QUERY_STRING']. "POST:");
sexhack_log($_POST);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment