ฉันตั้งโปรแกรมปลั๊กอินฟิลด์แบบกำหนดเองสำหรับ Virtuemart 2.6.6 ซึ่งแสดงพารามิเตอร์บางตัวบนหน้าผลิตภัณฑ์ เช่น "ขนาด" และพารามิเตอร์นั้นก็เป็นตัวแปรรถเข็นเช่นกัน
บทความนี้ช่วยได้มาก:
https://www.spiralscripts.co.uk/Joomla-Tips/custom-plugin-fields-in-virtuemart-2-2.html
และแน่นอน ฟอรัม stackoverflow และปลั๊กอิน VM แบบกำหนดเองที่เป็นค่าเริ่มต้นจากโรงงาน
ทุกอย่างใช้งานได้ (ขนาดจะแสดงในมุมมองรายละเอียดสินค้าและในรถเข็นเมื่อคุณเพิ่มผลิตภัณฑ์ลงไป) แต่สิ่งหนึ่งที่:
- หลังจากส่งคำสั่งซื้อแล้วพารามิเตอร์ไม่แสดงในรายละเอียดคำสั่งซื้อดังนั้นฉันจึงไม่ทราบว่าซื้อสินค้าขนาดใด
ฉันวางฟังก์ชันต่อไปนี้ลงในปลั๊กอิน แต่ไม่สามารถแก้ไขปัญหาได้:
function plgVmOnViewCart($product, $row, &$html)
{
if (empty($product->productCustom->custom_element) or $product->productCustom->custom_element != $this->_name) return '';
if (!$plgParam = $this->GetPluginInCart($product)) return false ;
$html .= '<div class="parameterek_attributes">';
foreach ($plgParam as $attributes) {
foreach ($attributes as $k => $attribute) {
if ($k =='child_id') continue;
if ($k == 'custom_param_default3') $name = 'Veľkosť'; else $name = '';
$html .='<span class="parameterek_attribute"> '.$name.': '.JText::_($attribute).' </span>';
}
}
$html.='</div>';
return true;
}
/**
*
* shopper order display BackEnd
*/
function plgVmDisplayInOrderBE($item, $row,&$html)
{
if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return '';
if(!empty($productCustom)){
$item->productCustom = $productCustom;
}
$this->plgVmOnViewCart($item, $row,$html);
}
/**
*
* shopper order display FrontEnd
*/
function plgVmDisplayInOrderFE($item, $row,&$html)
{
if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return '';
$this->plgVmOnViewCart($item, $row,$html);
}
ลงในตารางฐานข้อมูลที่เรียกว่า #__virtuemart_order_items ถูกบันทึกค่า: บางอย่างเช่น:
{"357":"5"}
แต่ควรมีลักษณะดังนี้:
{"357":ไซส์เอ็ม"}
ฉันเห็นว่าฟังก์ชันหลักคือ GetPluginInCart($product) และเมื่อฉันพิมพ์พารามิเตอร์ $product->ในฟังก์ชันนั้น ฉันได้ผลลัพธ์นี้ เมื่อฉันดำเนินการตามขั้นตอนการชำระเงิน:
Array
(
[0] => Array
(
[parameterek] => Array
(
[custom_param_default3] => L
)
)
)
แต่หลังจากที่ฉันสั่งซื้อเสร็จแล้วและไปที่รายละเอียดการสั่งซื้อ $product->param จะมีค่านี้:
Array
(
[357] => 5
)
- ดังนั้นฉันคิดว่าก่อนที่ฉันจะเสร็จสิ้นคำสั่งซื้อ ฉันจะต้องจัดการพารามิเตอร์ผลิตภัณฑ์ที่เลือกและแปลงให้อยู่ในรูปแบบที่ถูกต้อง แต่ฉันไม่รู้ว่าต้องทำอย่างไร
บนเว็บไซต์ต่อไปนี้ https://dev.virtuemart.net/projects/virtuemart/wiki/Product_Plugins
ฉันพบฟังก์ชั่น:
plgVmOnViewCartOrder($product, $param,$productCustom, $row)
handel $param before adding it in the order
return $param;
แต่เมื่อฉันค้นหาสตริง "plgVmOnViewCartOrder" ในการติดตั้ง virtuemart ทั้งหมด ไม่พบ ดังนั้นจึงหมายความว่าไม่ได้เปิดตัว (?)
หากใครสามารถช่วยฉันหรือส่งเอกสารที่เป็นธรรมได้จะดีมาก ขอบคุณ!