ตัวอย่างการสร้างmoduleเองในprestashop


ตัวอย่างที่จะสร้างจะเป็นmoduleที่แสดงรูปภาพทางคอลัมด้านซ้ายครับ

1.สร้างโฟลเดอร์ "example" ในโฟลเดอร์ module/
2.ใช้Notepadหรือ Dreamweaver สร้างไฟล์ example.tplแล้วใส่โค้ดนี้ลงใน example.tpl


<div class="block">
<h4>Example</h4>
<div class="block_content" style="padding:0px;">
Example Prestashop Module
<a href="http://www.siampresta.blogspot.com/">
<img src="{$module_dir}example.jpg" border="0" />
</a>
</div>
</div>


4.สร้างไฟล์ example.php แล้วใส่โค้ดนี้


<?phpclass Example extends Module{
function __construct()
{
$this->name = 'Example'; //ชื่อmodule
$this->tab = 'Blocks';
$this->version = 1.0; //เวอร์ชั่นของmodule

parent::__construct();

$this->page = basename(__FILE__, '.php'); //ที่อยู่ของไฟล์php
$this->displayName = $this->l('Block Example'); //แสดงชื่อmoduleในlistรายการ
$this->description = $this->l('Add a Example block'); //รายละเอียดmodule
}

function install() //ฟังชั่นนี้เอาไว้เช็คว่าติดตั้งหรือยัง และตำแหน่งของmodule
{
if (!parent::install())
return false;
if (!$this->registerHook('leftColumn'))
return false;
return true;
}


function hookLeftColumn($params)
{
return $this->display(__FILE__, 'example.tpl'); //ที่อยู่ไฟล์Templateของmodule
}

}
?>

5.หาไฟล์รูปอะไรก็ได้แล้วนำไปไว้ในโฟลเดอร์moduleของเราและตั้งชื่อไฟล์เป็น example.jpg

6.เข้าไป back office >> Module แล้วทำการติดตั้งได้เลยครับ

ตัวอย่างไฟล์

0 comments:

Post a Comment

หัวข้อที่เกี่ยวข้อง

top