ฟิลด์ที่กำหนดเองของ VirtueMart 2.6.6 (ตัวแปรรถเข็น) ไม่แสดงในรายละเอียดการสั่งซื้อ

ฉันตั้งโปรแกรมปลั๊กอินฟิลด์แบบกำหนดเองสำหรับ 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 ทั้งหมด ไม่พบ ดังนั้นจึงหมายความว่าไม่ได้เปิดตัว (?)

หากใครสามารถช่วยฉันหรือส่งเอกสารที่เป็นธรรมได้จะดีมาก ขอบคุณ!


person Gregory    schedule 30.07.2014    source แหล่งที่มา


คำตอบ (1)


ฉันคิดว่าฉันได้แก้ไขปัญหาของฉันแล้ว อะไรคือ:

ในฟังก์ชัน plgVmOnDisplayProductVariantFE ฉันทำผิดพลาด ฉันไม่ได้ใช้ตัวเรนเดอร์เลย์เอาต์ ซึ่งสร้างออบเจ็กต์ $viewData พร้อมตัวแปร virtuemart_customfield_id

จากนั้นในเลย์เอาต์ของปลั๊กอิน ชื่อฟิลด์อินพุตจะต้องเป็นดังนี้:

<input 
  class="parameterekInput" 
  type="radio" 
  id="plugin_param['.$viewData[0]->virtuemart_customfield_id.']['.$this->_name.']['.$c.']" 
  name="customPlugin['.$viewData[0]->virtuemart_customfield_id.']['.$this->_name.'][custom_param_default3]" 
  value="'.$size.'" />

ดังนั้นแอตทริบิวต์ name ควรเป็นดังนี้:

  • customPlugin['.$viewData[0]->virtuemart_customfield_id.']['.$this->_name.'][อะไรก็ได้]

การใช้งานที่ถูกต้องของฟังก์ชัน plgVmOnDisplayProductVariantFE คือการใช้นิพจน์:

  • $group->display .= $this->renderByLayout('default',array($field,&$idx,&$group )

นี่คือฟังก์ชันทั้งหมดที่มีการแสดงออกที่ถูกต้อง:

function plgVmOnDisplayProductVariantFE ($field, &$idx, &$group) {
    if ($field->custom_element != $this->_name) return '';

    $this->getCustomParams($field);

        $this->getPluginCustomData($field, $field->virtuemart_product_id);

        $group->display .= $this->renderByLayout('default',array($field,&$idx,&$group ) );

    return true;
  }

ตอนนี้เมื่อฉัน print_r -ing $product->param ในฟังก์ชัน GetPluginInCart($product) ฉันจะได้รับสิ่งนี้:

Array
(
[273] => Array  //previously the key was Zero, now it is 273, value of virtuemart_customfield_id
    (
        [parameterek] => Array
            (
                [custom_param_default3] => L
            )

    )

)

...และดีใจที่ได้เดินหน้าโครงการต่อไป :)

person Gregory    schedule 31.07.2014