但是我在这里学习,我已经坚持这个功能一个月没有任何进展,没有结果。
所以,我有两个插件,一个名称“花哨的产品设计师”是一个Woocommerce产品编辑器,客户可以在您的网站上创建自己的定制产品,第二个是“ Dokan “是一个多市场,客户可以像卖家一样行事,建立自己的产品,价格,命名产品等。
现在,我想整合两个插件,想要在我的网站上销售的客户,他们需要通过“Fancy Product Designer”创建他们的产品,然后填写该产品的信息(名称,价格) ,desc)在Dokan上添加产品页面。简单来说,我想将“花式产品设计师”生成的图像用作“Dokan”上的产品特色图片添加产品页面,其中两者都在不同的页面上。
因为我是一个新手而且没有编码的基本技能,我不知道如何实现代码,代码使用的代码,代码产生的结果等等。但是这里有一些实现该函数所需的代码。
以下是“ Fancy Product Designer”的一些代码
/**
* Creates an image of the current showing product.
*
* @method createImage
* @param {boolean} [openInBlankPage= true] Opens the image in a Pop-up window.
* @param {boolean} [forceDownload=false] Downloads the image to the user's computer.
* @param {string} [backgroundColor=transparent] The background color as hexadecimal value. For 'png' you can also use 'transparent'.
* @param {string} [options] See fabricjs documentation http://fabricjs.com/docs/fabric.Canvas.html#toDataURL.
*/
this.createImage = function(openInBlankPage, forceDownload, backgroundColor, options) {
if(typeof(openInBlankPage)==='undefined') openInBlankPage = true;
if(typeof(forceDownload)==='undefined') forceDownload = false;
backgroundColor = typeof backgroundColor !== 'undefined' ? backgroundColor : 'transparent';
options = typeof options !== 'undefined' ? options : {};
format = options.format === undefined ? 'png' : options.format;
instance.getProductDataURL(function(dataURL) {
var image = new Image();
image.src = dataURL;
image.onload = function() {
if(openInBlankPage) {
var popup = window.open('','_blank');
FPDUtil.popupBlockerAlert(popup, instance);
popup.document.title = "Product Image";
$(popup.document.body).append('<img src="'+this.src+'" download="product.'+format+'" />');
if(forceDownload) {
window.location.href = popup.document.getElementsByTagName('img')[0].src.replace('image/'+format+'', 'image/octet-stream');
}
}
}
}, backgroundColor, options);
/**
我不知道它是否被使用,但它的代码是生成视图(Product Canvas / A层图像,后来加入并成为Product Image)到dataURL
/**
* Gets the views as data URL.
*
* @method getViewsDataURL
* @param {Function} callback A function that will be called when the data URL is created. The function receives the data URL.
* @param {string} [backgroundColor=transparent] The background color as hexadecimal value. For 'png' you can also use 'transparent'.
* @param {string} [options] See fabricjs documentation http://fabricjs.com/docs/fabric.Canvas.html#toDataURL.
* @return {array} An array with all views as data URLs.
*/
this.getViewsDataURL = function(callback, backgroundColor, options) {
callback = typeof callback !== 'undefined' ? callback : function() {};
backgroundColor = typeof backgroundColor !== 'undefined' ? backgroundColor : 'transparent';
options = typeof options !== 'undefined' ? options : {};
var dataURLs = [];
for(var i=0; i < instance.viewInstances.length; ++i) {
instance.viewInstances[i].toDataURL(function(dataURL) {
dataURLs.push(dataURL);
if(dataURLs.length === instance.viewInstances.length) {
callback(dataURLs);
}
}, backgroundColor, options, instance.watermarkImg);
}
};
};
/**
* Creates all views in one data URL. The different views will be positioned below each other.
*
* @method getProductDataURL
* @param {Function} callback A function that will be called when the data URL is created. The function receives the data URL.
* @param {String} [backgroundColor=transparent] The background color as hexadecimal value. For 'png' you can also use 'transparent'.
* @param {Object} [options] See fabricjs documentation http://fabricjs.com/docs/fabric.Canvas.html#toDataURL.
* @example fpd.getProductDataURL( function(dataURL){} );
*/
this.getProductDataURL = function(callback, backgroundColor, options) {
callback = typeof callback !== 'undefined' ? callback : function() {};
backgroundColor = typeof backgroundColor !== 'undefined' ? backgroundColor : 'transparent';
options = typeof options !== 'undefined' ? options : {};
//check
if(instance.viewInstances.length === 0) { callback('') }
$body.append('<canvas id="fpd-hidden-canvas"></canvas>');
var printCanvas = new fabric.Canvas('fpd-hidden-canvas', {
containerClass: 'fpd-hidden fpd-hidden-canvas',
enableRetinaScaling: true
}),
viewCount = 0;
function _addCanvasImage(viewInstance) {
if(viewInstance.options.stageWidth > printCanvas.getWidth()) {
printCanvas.setDimensions({width: viewInstance.options.stageWidth});
}
viewInstance.toDataURL(function(dataURL) {
fabric.Image.fromURL(dataURL, function(img) {
printCanvas.add(img);
if(viewCount > 0) {
img.setTop(printCanvas.getHeight());
printCanvas.setDimensions({height: (printCanvas.getHeight() + viewInstance.options.stageHeight)});
}
viewCount++;
if(viewCount < instance.viewInstances.length) {
_addCanvasImage(instance.viewInstances[viewCount]);
}
else {
callback(printCanvas.toDataURL(options));
printCanvas.dispose();
$body.children('.fpd-hidden-canvas, #fpd-hidden-canvas').remove();
if(instance.currentViewInstance) {
instance.currentViewInstance.resetCanvasSize();
}
}
});
以下是添加精选图片的“ Dokan ”插件代码(注意:我不知道这是否有问题,但dokan只能从wordpress媒体上传精选图片,即使有上传选项,但上传的文件也必须在我的电脑上。)
featuredImage: {
addImage: function(e) {
e.preventDefault();
var self = $(this);
if ( product_featured_frame ) {
product_featured_frame.open();
return;
}
product_featured_frame = wp.media({
// Set the title of the modal.
title: 'Upload featured image',
button: {
text: 'Set featured image',
}
});
product_featured_frame.on('select', function() {
var selection = product_featured_frame.state().get('selection');
selection.map( function( attachment ) {
attachment = attachment.toJSON();
// set the image hidden id
self.siblings('input.dokan-feat-image-id').val(attachment.id);
// set the image
var instruction = self.closest('.instruction-inside');
var wrap = instruction.siblings('.image-wrap');
// wrap.find('img').attr('src', attachment.sizes.thumbnail.url);
wrap.find('img').attr('src', attachment.url);
instruction.addClass('dokan-hide');
wrap.removeClass('dokan-hide');
});
});
product_featured_frame.open();
},
removeImage: function(e) {
e.preventDefault();
var self = $(this);
var wrap = self.closest('.image-wrap');
var instruction = wrap.siblings('.instruction-inside');
instruction.find('input.dokan-feat-image-id').val('0');
wrap.addClass('dokan-hide');
instruction.removeClass('dokan-hide');
}
}
如果我提供的代码对您没有帮助,请向我询问另一个功能,我会寻找它。
请帮助我在html或php或两者上实现代码,以便它将从一个重定向到另一个。我之前看过How to pass extra variables in URL with Wordpress,我认为它可以提供帮助,所以我决定尝试使用参数来定义来自其他网站的精选图片,但是当我尝试在“Dokan”上使用它时添加产品页面? feat_image_id = https://imageurl.com或?dokan-featured-image = https://imageurl.com以及可能的一些参数(我忘了它是什么)但该页面上没有任何反应。
非常感谢您的关注,感谢所有想要帮助我的人