· 7 years ago · Sep 27, 2018, 04:30 PM
1<?php
2
3$installer = $this;
4
5try {
6 $installer->startSetup();
7
8 $resource = Mage::getSingleton('core/resource');
9 $newTable = $resource->getTableName('homepageslider/records');
10
11 $installer->run("
12 CREATE TABLE IF NOT EXISTS {$newTable} (
13 entity_id INT(10) UNSIGNED PRIMARY KEY,
14 hp_counter INT(6) UNSIGNED,
15 hp_limit INT(6) UNSIGNED,
16 hp_lastvisit TIMESTAMP
17 );
18 ");
19
20 $sql = [];
21 $sql[] = "INSERT INTO {$newTable}";
22 $sql[] = "(entity_id, hp_counter, hp_limit, hp_lastvisit)";
23 $sql[] = "VALUES";
24
25 $products = Mage::getModel('catalog/product');
26 foreach ($products as $product) {
27 if ($product->hasCzSupplier()) {
28 $sql[] = "(" . $product->getEntityId() . ", 0, 2000, NULL)";
29 }
30 }
31
32 $installer->run(implode(' ', $sql));
33
34
35 $installer->endSetup();
36}
37catch (Exception $e) {
38 Mage::logException($e);
39}