From d738ce62b6fa73e94b7885ffeaa7811705509725 Mon Sep 17 00:00:00 2001 From: khanh97dev Date: Mon, 4 Dec 2023 09:18:00 +0700 Subject: [PATCH] add my module --- app/code/Kai/Banner.zip | Bin 0 -> 10088 bytes app/code/Kai/Banner/Api/BannerRepository.php | 177 +++++++++++ .../Banner/Api/BannerRepositoryInterface.php | 23 ++ app/code/Kai/Banner/Api/Helper.php | 7 + app/code/Kai/Banner/Block/Adminhtml/Index.php | 43 +++ .../Controller/Adminhtml/Index/Index.php | 24 ++ app/code/Kai/Banner/Model/KaiBanner.php | 36 +++ .../Kai/Banner/Model/KaiBannerCollection.php | 17 + .../Banner/Model/KaiBannerResourceModel.php | 15 + app/code/Kai/Banner/Model/KaiBannerValues.php | 64 ++++ .../Model/Serialize/Serializer/Json.php | 36 +++ app/code/Kai/Banner/Setup/UpgradeData.php | 58 ++++ app/code/Kai/Banner/Setup/UpgradeSchema.php | 94 ++++++ app/code/Kai/Banner/etc/adminhtml/acl.xml | 25 ++ app/code/Kai/Banner/etc/adminhtml/menu.xml | 27 ++ app/code/Kai/Banner/etc/adminhtml/routes.xml | 11 + app/code/Kai/Banner/etc/di.xml | 12 + app/code/Kai/Banner/etc/module.xml | 4 + app/code/Kai/Banner/etc/webapi.xml | 15 + app/code/Kai/Banner/registration.php | 6 + .../layout/kai_banner_index_index.xml | 14 + .../view/adminhtml/templates/index.phtml | 299 ++++++++++++++++++ .../Banner/view/frontend/layout/default.xml | 13 + .../Kai/Helloworld/Controller/Index/Index.php | 23 ++ app/code/Kai/Helloworld/etc/module.xml | 12 + app/code/Kai/Helloworld/registration.php | 6 + app/code/Kai/Helloworld/routes.xml | 14 + .../frontend/layout/module_index_index.xml | 8 + .../templates/module_index_index.phtml | 1 + app/code/Kai/Product/Block/Custom.php | 27 ++ .../Product/Block/Product/View/CustomTab.php | 59 ++++ .../Kai/Product/Controller/Index/Index.php | 23 ++ app/code/Kai/Product/Setup/InstallData.php | 52 +++ .../Kai/Product/etc/catalog_attributes.xml | 10 + app/code/Kai/Product/etc/frontend/routes.xml | 7 + app/code/Kai/Product/etc/module.xml | 12 + app/code/Kai/Product/registration.php | 6 + app/code/Kai/Product/routes.xml | 14 + .../frontend/layout/catalog_product_view.xml | 20 ++ .../frontend/layout/module_index_index.xml | 8 + .../product/view/custom_attribute.phtml | 7 + .../templates/product/view/custom_tab.phtml | 22 ++ .../templates/product/view/header.phtml | 148 +++++++++ .../view/frontend/templates/sample.phtml | 1 + app/code/Kai/Widget/Block/Widget/MyWidget.php | 10 + app/code/Kai/Widget/etc/module.xml | 4 + app/code/Kai/Widget/etc/widget.xml | 13 + app/code/Kai/Widget/registration.php | 6 + .../view/frontend/templates/mywidget.phtml | 4 + .../view/layout/my_module_index_index.xml | 11 + 50 files changed, 1548 insertions(+) create mode 100755 app/code/Kai/Banner.zip create mode 100755 app/code/Kai/Banner/Api/BannerRepository.php create mode 100755 app/code/Kai/Banner/Api/BannerRepositoryInterface.php create mode 100755 app/code/Kai/Banner/Api/Helper.php create mode 100755 app/code/Kai/Banner/Block/Adminhtml/Index.php create mode 100755 app/code/Kai/Banner/Controller/Adminhtml/Index/Index.php create mode 100755 app/code/Kai/Banner/Model/KaiBanner.php create mode 100755 app/code/Kai/Banner/Model/KaiBannerCollection.php create mode 100755 app/code/Kai/Banner/Model/KaiBannerResourceModel.php create mode 100755 app/code/Kai/Banner/Model/KaiBannerValues.php create mode 100755 app/code/Kai/Banner/Model/Serialize/Serializer/Json.php create mode 100755 app/code/Kai/Banner/Setup/UpgradeData.php create mode 100755 app/code/Kai/Banner/Setup/UpgradeSchema.php create mode 100755 app/code/Kai/Banner/etc/adminhtml/acl.xml create mode 100755 app/code/Kai/Banner/etc/adminhtml/menu.xml create mode 100755 app/code/Kai/Banner/etc/adminhtml/routes.xml create mode 100755 app/code/Kai/Banner/etc/di.xml create mode 100755 app/code/Kai/Banner/etc/module.xml create mode 100755 app/code/Kai/Banner/etc/webapi.xml create mode 100755 app/code/Kai/Banner/registration.php create mode 100755 app/code/Kai/Banner/view/adminhtml/layout/kai_banner_index_index.xml create mode 100755 app/code/Kai/Banner/view/adminhtml/templates/index.phtml create mode 100755 app/code/Kai/Banner/view/frontend/layout/default.xml create mode 100755 app/code/Kai/Helloworld/Controller/Index/Index.php create mode 100755 app/code/Kai/Helloworld/etc/module.xml create mode 100755 app/code/Kai/Helloworld/registration.php create mode 100755 app/code/Kai/Helloworld/routes.xml create mode 100755 app/code/Kai/Helloworld/view/frontend/layout/module_index_index.xml create mode 100755 app/code/Kai/Helloworld/view/frontend/templates/module_index_index.phtml create mode 100755 app/code/Kai/Product/Block/Custom.php create mode 100755 app/code/Kai/Product/Block/Product/View/CustomTab.php create mode 100755 app/code/Kai/Product/Controller/Index/Index.php create mode 100755 app/code/Kai/Product/Setup/InstallData.php create mode 100755 app/code/Kai/Product/etc/catalog_attributes.xml create mode 100755 app/code/Kai/Product/etc/frontend/routes.xml create mode 100755 app/code/Kai/Product/etc/module.xml create mode 100755 app/code/Kai/Product/registration.php create mode 100755 app/code/Kai/Product/routes.xml create mode 100755 app/code/Kai/Product/view/frontend/layout/catalog_product_view.xml create mode 100755 app/code/Kai/Product/view/frontend/layout/module_index_index.xml create mode 100755 app/code/Kai/Product/view/frontend/templates/product/view/custom_attribute.phtml create mode 100755 app/code/Kai/Product/view/frontend/templates/product/view/custom_tab.phtml create mode 100755 app/code/Kai/Product/view/frontend/templates/product/view/header.phtml create mode 100755 app/code/Kai/Product/view/frontend/templates/sample.phtml create mode 100755 app/code/Kai/Widget/Block/Widget/MyWidget.php create mode 100755 app/code/Kai/Widget/etc/module.xml create mode 100755 app/code/Kai/Widget/etc/widget.xml create mode 100755 app/code/Kai/Widget/registration.php create mode 100755 app/code/Kai/Widget/view/frontend/templates/mywidget.phtml create mode 100755 app/code/Kai/Widget/view/layout/my_module_index_index.xml diff --git a/app/code/Kai/Banner.zip b/app/code/Kai/Banner.zip new file mode 100755 index 0000000000000000000000000000000000000000..0a484283392d6cb7f8887755df226f936d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nRra`Cm~)_<4pgKhMm+t9hP_&{4Fhhi{EB||39F; zIQ~sNHX`Hn-+{KMUQEP^{tL(Vv)pbDd=qiQa!-KM#y_Ef!H8pGtT(Z~9^S`%JK1k0 zEc3PPiLtj0=>=9FefvMr*s;(k3HQ=y8|{}Nu`+spOfYCSKfh_k4ZrFAC(J!vn9JhB zu%8Qe640br3ReJU&wpIFLD*sX&W5+YkNd9){JX;L6n+Rx_yo4_?E&Ebg8_qfGvb&A zWC3I8unqHvAIC(i?6KfA`Dcji#S~+rp@{#2w#ge~!bwRwNdG$`!Jyq7DkfYVP$@AS zw5{AWqlyWr=0RjSw2ywfnMq8*A>b$j1MoLbi3t(wyr#(f&$s}Cb`yV?5M#jLi2<=q z17gAi&$qnh-ba(&1RN$z4Zz%Bz--fTm@u615u&txwAoEnVZsm`*n-(fTwww==r_BBDW3kRZ_>Zpmc8hzP4OFbsCK9LUE~!eUjEf^t=Ipw+g^Ob zCf9U>ANTxf<}jr{26y?N{-^Wz;wUhsr|givoj8~{BuXxiC-=eG&1+!dwEY$5 z&jf)9w;101YQJ)@n+w^5+i()qL2RRKtFqXFQ_V*`^=|vAxqEWk1l|Z9 jUi!aSbMM%ZBlauZyL1u&y%Pw;2K-F`#oiha3j+NQUYRjh literal 0 HcmV?d00001 diff --git a/app/code/Kai/Banner/Api/BannerRepository.php b/app/code/Kai/Banner/Api/BannerRepository.php new file mode 100755 index 00000000..9b52ab45 --- /dev/null +++ b/app/code/Kai/Banner/Api/BannerRepository.php @@ -0,0 +1,177 @@ +kaiBannerModel = $kaiBannerModel; + $this->kaiBannerResourceModel = $kaiBannerResourceModel; + $this->kaiBannerCollection = $kaiBannerCollection; + $this->authorization(); + } + + private function authorization() + { + $headers = apache_request_headers(); + $apiKey = \Kai\Banner\Api\Helper::API_KEY; + + foreach ($headers as $key => $value) { + $key = strtolower($key); + if ('api_key' === $key && $value === $apiKey) { + return true; + } + } + + header('HTTP/1.1 401 Unauthorized'); + header('Accept: application/json'); + header('Content-Type: application/json'); + die( + json_encode(['message' => 'unauthorized']) + ); + } + + private function responseOk(array $data) + { + header('HTTP/1.1 200 Ok'); + header('Accept: application/json'); + header('Content-Type: application/json'); + die(json_encode($data)); + } + + private function responseFail(array $data) + { + header('HTTP/1.1 400 Bad request'); + header('Accept: application/json'); + header('Content-Type: application/json'); + die(json_encode($data)); + } + + private function responseMethodFail() + { + header('HTTP/1.1 400 bad request'); + header('Accept: application/json'); + header('Content-Type: application/json'); + die(json_encode([ + 'status' => false, + 'message' => 'Param ?method=... not exist!' + ])); + } + + public function getData() + { + $method = $_GET['method'] ?? null; + + if ($method === 'show') { + $id = $_GET['id'] ?? 0; + return $this->responseOk([ + 'status' => true, + 'data' => $this + ->kaiBannerCollection + ->getItemById($id) + ->getData() + ]); + } + + if ($method === 'all') { + return $this->responseOk([ + 'status' => true, + 'data' => $this + ->kaiBannerCollection + ->getData() + ]); + } + + if ($method === 'delete') { + $id = $_GET['id'] ?? 0; + $model = $this->kaiBannerModel->setId($id); + + try { + $this->kaiBannerResourceModel->delete($model); + return $this->responseOk([ + 'status' => true, + ]); + } catch (\Exception $ex) { + $this->kaiBannerResourceModel->rollBack(); + return $this->responseFail([ + 'status' => false, + 'message' => $ex->getMessage() + ]); + } + } + + return $this->responseMethodFail(); + } + + public function postData() + { + $method = $_GET['method'] ?? null; + parse_str( + string: file_get_contents('php://input'), + result: $payload + ); + + if ($method === 'create') { + $model = $this->kaiBannerModel; + try { + foreach ($payload as $key => $value) { + $model->setData($key, $value); + } + $this->kaiBannerResourceModel->save($model); + + return $this->responseOk([ + 'status' => true, + 'data' => $this + ->kaiBannerCollection + ->getItemById($model->getId()) + ->getData() + ]); + } catch (\Exception $ex) { + return $this->responseFail([ + 'status' => false, + 'message' => $ex->getMessage() + ]); + } + } + + if ($method === 'update') { + $id = $_GET['id'] ?? 0; + $model = $this->kaiBannerModel->setId($id); + + try { + foreach ($payload as $key => $value) { + $model->setData($key, $value); + } + $this->kaiBannerResourceModel->save($model); + + return $this->responseOk([ + 'status' => true, + 'data' => $this + ->kaiBannerCollection + ->getItemById($model->getId()) + ->getData() + ]); + } catch (\Exception $ex) { + return $this->responseFail([ + 'status' => false, + 'message' => $ex->getMessage() + ]); + } + } + + return $this->responseMethodFail(); + } +} diff --git a/app/code/Kai/Banner/Api/BannerRepositoryInterface.php b/app/code/Kai/Banner/Api/BannerRepositoryInterface.php new file mode 100755 index 00000000..bfb34914 --- /dev/null +++ b/app/code/Kai/Banner/Api/BannerRepositoryInterface.php @@ -0,0 +1,23 @@ +urlInterface = $urlInterface; + $this->kaiBanner = $kaiBanner; + $this->kaiBannerResourceModel = $kaiBannerResourceModel; + $this->kaiBannerCollection = $kaiBannerCollection; + parent::__construct($context, $data); + } + + public function getSecretKey() + { + return $this->urlInterface->getSecretKey(); + } + + public function getApiKey() + { + return \Kai\Banner\Api\Helper::API_KEY; + } + + public function getAll() + { + return $this->kaiBannerCollection->getData(); + } +} diff --git a/app/code/Kai/Banner/Controller/Adminhtml/Index/Index.php b/app/code/Kai/Banner/Controller/Adminhtml/Index/Index.php new file mode 100755 index 00000000..f194e530 --- /dev/null +++ b/app/code/Kai/Banner/Controller/Adminhtml/Index/Index.php @@ -0,0 +1,24 @@ +resultPageFactory = $resultPageFactory; + parent::__construct($context); + } + + public function execute() + { + $resultPage = $this->resultPageFactory->create(); + $resultPage->getConfig()->getTitle()->prepend(__('Banner')); + return $resultPage; + } +} diff --git a/app/code/Kai/Banner/Model/KaiBanner.php b/app/code/Kai/Banner/Model/KaiBanner.php new file mode 100755 index 00000000..ecbc2642 --- /dev/null +++ b/app/code/Kai/Banner/Model/KaiBanner.php @@ -0,0 +1,36 @@ +_init( + resourceModel: KaiBannerResourceModel::class + ); + } + +} + +final class KaiBannerFactory extends Factory +{ + protected $objectManager; + protected $instanceName; + + public function __construct(ObjectManagerInterface $objectManager, $instanceName = KaiBanner::class) + { + $this->objectManager = $objectManager; + $this->instanceName = $instanceName; + } + + public function create(array $arguments = [], AbstractDb $resource = null) + { + return $this->objectManager->create($this->instanceName, $arguments, $resource); + } +} diff --git a/app/code/Kai/Banner/Model/KaiBannerCollection.php b/app/code/Kai/Banner/Model/KaiBannerCollection.php new file mode 100755 index 00000000..41e6233e --- /dev/null +++ b/app/code/Kai/Banner/Model/KaiBannerCollection.php @@ -0,0 +1,17 @@ +_init( + model: KaiBanner::class, + resourceModel: KaiBannerResourceModel::class + ); + } +} diff --git a/app/code/Kai/Banner/Model/KaiBannerResourceModel.php b/app/code/Kai/Banner/Model/KaiBannerResourceModel.php new file mode 100755 index 00000000..b7e22a14 --- /dev/null +++ b/app/code/Kai/Banner/Model/KaiBannerResourceModel.php @@ -0,0 +1,15 @@ +_init( + mainTable:'kai_banner', + idFieldName:'id' + ); + } +} diff --git a/app/code/Kai/Banner/Model/KaiBannerValues.php b/app/code/Kai/Banner/Model/KaiBannerValues.php new file mode 100755 index 00000000..7073f97e --- /dev/null +++ b/app/code/Kai/Banner/Model/KaiBannerValues.php @@ -0,0 +1,64 @@ +collection = $collection; + } + + public function getAllOptions() + { + $data = $this->collection->getData(); + $options = [ + [ + 'label' => 'Select option!', + 'value' => '', + ] + ]; + + foreach ($data as $record) { + $options[] = [ + 'label' => $record['id'], + 'value' => $record['title'], + ]; + }; + + $this->_options = $options; + return $options; + } + + public function getOptionText($value) + { + foreach ($this->getAllOptions() as $option) { + if ($option['value'] == $value) { + return $option['label']; + } + } + return false; + } + + public function getFlatColumns() + { + $attributeCode = $this->getAttribute()->getAttributeCode(); + return [ + $attributeCode => [ + 'unsigned' => false, + 'default' => null, + 'extra' => null, + 'type' => Table::TYPE_INTEGER, + 'nullable' => true, + 'comment' => 'Kai Banner ' . $attributeCode . ' column', + ], + ]; + } +} diff --git a/app/code/Kai/Banner/Model/Serialize/Serializer/Json.php b/app/code/Kai/Banner/Model/Serialize/Serializer/Json.php new file mode 100755 index 00000000..9af00dd5 --- /dev/null +++ b/app/code/Kai/Banner/Model/Serialize/Serializer/Json.php @@ -0,0 +1,36 @@ +_eavSetupFactory = $eavSetupFactory; + $this->_attributeRepositoryInterface = $attributeRepositoryInterface; + $this->_attributeSetupFactory = $attributeSetupFactory; + } + + public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) + { + try { + $this->_attributeRepositoryInterface->get(Product::ENTITY, 'kai_banner'); + } catch (\Exception $ex) { + + $setup->startSetup(); + $eavSetup = $this->_eavSetupFactory->create(['setup' => $setup]); + $eavSetup->addAttribute( + Product::ENTITY, + 'kai_banner', + [ + 'input' => 'select', + 'type' => 'varchar', + 'label' => 'Banner', + 'required' => false, + 'visible' => true, + 'user_defined' => true, + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'used_in_product_listing' => true, + 'apply_to' => '', + 'source' => \Kai\Banner\Model\KaiBannerValues::class, + 'global' => ScopedAttributeInterface::SCOPE_GLOBAL, + 'group' => 'General', + ] + ); + $setup->endSetup(); + } + } +} diff --git a/app/code/Kai/Banner/Setup/UpgradeSchema.php b/app/code/Kai/Banner/Setup/UpgradeSchema.php new file mode 100755 index 00000000..414a018b --- /dev/null +++ b/app/code/Kai/Banner/Setup/UpgradeSchema.php @@ -0,0 +1,94 @@ +startSetup(); + + $tableName = $installer->getTable('kai_banner'); + + if ($installer->tableExists($tableName)) { + $installer->getConnection()->dropTable($tableName); + } + + $table = $installer->getConnection() + ->newTable($tableName) + ->addColumn( + 'id', + Table::TYPE_INTEGER, + null, + [ + 'identity' => true, + 'unsigned' => true, + 'nullable' => false, + 'primary' => true, + ], + 'ID' + ) + ->addColumn( + 'title', + Table::TYPE_TEXT, + null, + ['nullable' => false, 'default' => ''], + 'Title' + ) + ->addColumn( + 'html', + Table::TYPE_TEXT, + null, + ['nullable' => true, 'default' => ''], + 'htmlentities($str)' + ) + ->addColumn( + 'redirect', + Table::TYPE_TEXT, + null, + ['nullable' => true, 'default' => ''], + 'URL redirect' + ) + ->addColumn( + 'created_at', + Table::TYPE_TIMESTAMP, + null, + [ + 'nullable' => true, + 'default' => Table::TIMESTAMP_INIT, + ], + 'Created At' + ) + ->addColumn( + 'updated_at', + Table::TYPE_TIMESTAMP, + null, + [ + 'nullable' => true, + 'default' => Table::TIMESTAMP_INIT_UPDATE, + ], + 'Updated At' + ) + ->addColumn( + 'status', + Table::TYPE_SMALLINT, + null, + [ + 'nullable' => false, + 'default' => '0', + ], + 'Status' + )->setComment('Kai Banner Module'); + $installer->getConnection()->createTable($table); + $installer->endSetup(); + } +} diff --git a/app/code/Kai/Banner/etc/adminhtml/acl.xml b/app/code/Kai/Banner/etc/adminhtml/acl.xml new file mode 100755 index 00000000..7d4c29d1 --- /dev/null +++ b/app/code/Kai/Banner/etc/adminhtml/acl.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + diff --git a/app/code/Kai/Banner/etc/adminhtml/menu.xml b/app/code/Kai/Banner/etc/adminhtml/menu.xml new file mode 100755 index 00000000..0ac5d9fc --- /dev/null +++ b/app/code/Kai/Banner/etc/adminhtml/menu.xml @@ -0,0 +1,27 @@ + + + + + + + + + diff --git a/app/code/Kai/Banner/etc/adminhtml/routes.xml b/app/code/Kai/Banner/etc/adminhtml/routes.xml new file mode 100755 index 00000000..f77e81e8 --- /dev/null +++ b/app/code/Kai/Banner/etc/adminhtml/routes.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/app/code/Kai/Banner/etc/di.xml b/app/code/Kai/Banner/etc/di.xml new file mode 100755 index 00000000..445bac41 --- /dev/null +++ b/app/code/Kai/Banner/etc/di.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/app/code/Kai/Banner/etc/module.xml b/app/code/Kai/Banner/etc/module.xml new file mode 100755 index 00000000..484439d5 --- /dev/null +++ b/app/code/Kai/Banner/etc/module.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/code/Kai/Banner/etc/webapi.xml b/app/code/Kai/Banner/etc/webapi.xml new file mode 100755 index 00000000..8a2be1d5 --- /dev/null +++ b/app/code/Kai/Banner/etc/webapi.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/app/code/Kai/Banner/registration.php b/app/code/Kai/Banner/registration.php new file mode 100755 index 00000000..e2330539 --- /dev/null +++ b/app/code/Kai/Banner/registration.php @@ -0,0 +1,6 @@ + + + + + + + + diff --git a/app/code/Kai/Banner/view/adminhtml/templates/index.phtml b/app/code/Kai/Banner/view/adminhtml/templates/index.phtml new file mode 100755 index 00000000..fc6859b2 --- /dev/null +++ b/app/code/Kai/Banner/view/adminhtml/templates/index.phtml @@ -0,0 +1,299 @@ + "ID", + "name" => "id", + "type" => "text", + "hidden" => false, + "disabled" => true, + ], + [ + "label" => "Title", + "name" => "title", + "type" => "text", + "hidden" => false, + "disabled" => false, + ], + [ + "label" => "HTML", + "name" => "html", + "type" => "textarea", + "hidden" => false, + "disabled" => false, + ], + [ + "label" => "Redirect", + + "name" => "redirect", + "type" => "text", + "hidden" => false, + "disabled" => false, + ], + [ + "label" => "Created At", + "name" => "created_at", + "type" => "text", + "hidden" => false, + "disabled" => true, + ], + [ + "label" => "Updated At", + "name" => "updated_at", + "type" => "text", + "hidden" => false, + "disabled" => true, + ], + [ + "label" => "Status", + "name" => "status", + "type" => "text", + "hidden" => false, + "disabled" => true, + ], + [ + "label" => "Operation", + "type" => "text", + "hidden" => true, + "disabled" => true, + ], +]; +?> + + + + +
+ + + + + + + + + + + + + getAll() as $row): ?> + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + +
+
+
+ + + + + + diff --git a/app/code/Kai/Banner/view/frontend/layout/default.xml b/app/code/Kai/Banner/view/frontend/layout/default.xml new file mode 100755 index 00000000..a152e50c --- /dev/null +++ b/app/code/Kai/Banner/view/frontend/layout/default.xml @@ -0,0 +1,13 @@ + + + + + + + Kai - Banner + kai/banner/index + + + + + diff --git a/app/code/Kai/Helloworld/Controller/Index/Index.php b/app/code/Kai/Helloworld/Controller/Index/Index.php new file mode 100755 index 00000000..513165a5 --- /dev/null +++ b/app/code/Kai/Helloworld/Controller/Index/Index.php @@ -0,0 +1,23 @@ +resultPageFactory = $resultPageFactory; + } + + public function execute() + { + $resultPage = $this->resultPageFactory->create(); + return $resultPage; + } +} diff --git a/app/code/Kai/Helloworld/etc/module.xml b/app/code/Kai/Helloworld/etc/module.xml new file mode 100755 index 00000000..b724a917 --- /dev/null +++ b/app/code/Kai/Helloworld/etc/module.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/app/code/Kai/Helloworld/registration.php b/app/code/Kai/Helloworld/registration.php new file mode 100755 index 00000000..a3d13bb5 --- /dev/null +++ b/app/code/Kai/Helloworld/registration.php @@ -0,0 +1,6 @@ + + + + + + + + + diff --git a/app/code/Kai/Helloworld/view/frontend/layout/module_index_index.xml b/app/code/Kai/Helloworld/view/frontend/layout/module_index_index.xml new file mode 100755 index 00000000..c1198019 --- /dev/null +++ b/app/code/Kai/Helloworld/view/frontend/layout/module_index_index.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/app/code/Kai/Helloworld/view/frontend/templates/module_index_index.phtml b/app/code/Kai/Helloworld/view/frontend/templates/module_index_index.phtml new file mode 100755 index 00000000..93190772 --- /dev/null +++ b/app/code/Kai/Helloworld/view/frontend/templates/module_index_index.phtml @@ -0,0 +1 @@ +

Hello from Kai_Helloworld!

diff --git a/app/code/Kai/Product/Block/Custom.php b/app/code/Kai/Product/Block/Custom.php new file mode 100755 index 00000000..b221902a --- /dev/null +++ b/app/code/Kai/Product/Block/Custom.php @@ -0,0 +1,27 @@ +registry = $registry; + } + + public function getCustomAttribute() + { + $product = $this->registry->registry('current_product'); + // Replace 'your_custom_attribute_code' with your actual attribute code + return $product->getData('kai_attribute'); + } +} diff --git a/app/code/Kai/Product/Block/Product/View/CustomTab.php b/app/code/Kai/Product/Block/Product/View/CustomTab.php new file mode 100755 index 00000000..1fc12790 --- /dev/null +++ b/app/code/Kai/Product/Block/Product/View/CustomTab.php @@ -0,0 +1,59 @@ +getLayout() + ->createBlock("Magento\Framework\View\Element\Template") + ->setTemplate("Kai_Product::product/view/header.phtml") + ->toHtml(); + } + + public function getProductName() + { + $product = $this->getProduct(); + if ($product) { + $product->getName(); + } + return $product; + } + + public function getImage() + { + $product = $this->getProduct(); + + if ($product) { + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $helperImport = $objectManager->get('\Magento\Catalog\Helper\Image'); + + $imageUrl = $helperImport->init($product, 'product_page_image_small') + ->setImageFile($product->getSmallImage()) // image,small_image,thumbnail + ->resize(380) + ->getUrl(); + return $imageUrl; + } + return null; + } + + public function getPrice() + { + $product = $this->getProduct(); + if ($product) { + return $product->getFormattedPrice(); + } + return null; + } + + public function getCustomAttribute() + { + $product = $this->getProduct(); + // Replace 'your_custom_attribute_code' with your actual attribute code + return $product->getData('kai_attribute'); + } +} diff --git a/app/code/Kai/Product/Controller/Index/Index.php b/app/code/Kai/Product/Controller/Index/Index.php new file mode 100755 index 00000000..4d9016cf --- /dev/null +++ b/app/code/Kai/Product/Controller/Index/Index.php @@ -0,0 +1,23 @@ +resultPageFactory = $resultPageFactory; + } + + public function execute() + { + $resultPage = $this->resultPageFactory->create(); + return $resultPage; + } +} diff --git a/app/code/Kai/Product/Setup/InstallData.php b/app/code/Kai/Product/Setup/InstallData.php new file mode 100755 index 00000000..d21cb13f --- /dev/null +++ b/app/code/Kai/Product/Setup/InstallData.php @@ -0,0 +1,52 @@ +eavSetupFactory = $eavSetupFactory; + } + + public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) + { + $setup->startSetup(); + + $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); + $eavSetup->addAttribute( + Product::ENTITY, + 'kai_attribute', + [ + 'type' => 'varchar', + 'label' => 'Kai Attribute', + 'input' => 'text', + 'required' => false, + 'visible' => true, + 'user_defined' => true, + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'used_in_product_listing' => true, + 'apply_to' => '', + 'global' => ScopedAttributeInterface::SCOPE_GLOBAL, + 'group' => 'General', + ] + ); + + $setup->endSetup(); + } +} diff --git a/app/code/Kai/Product/etc/catalog_attributes.xml b/app/code/Kai/Product/etc/catalog_attributes.xml new file mode 100755 index 00000000..8dfde04f --- /dev/null +++ b/app/code/Kai/Product/etc/catalog_attributes.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/app/code/Kai/Product/etc/frontend/routes.xml b/app/code/Kai/Product/etc/frontend/routes.xml new file mode 100755 index 00000000..af375a63 --- /dev/null +++ b/app/code/Kai/Product/etc/frontend/routes.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/app/code/Kai/Product/etc/module.xml b/app/code/Kai/Product/etc/module.xml new file mode 100755 index 00000000..92abcaf7 --- /dev/null +++ b/app/code/Kai/Product/etc/module.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/app/code/Kai/Product/registration.php b/app/code/Kai/Product/registration.php new file mode 100755 index 00000000..ba69dd76 --- /dev/null +++ b/app/code/Kai/Product/registration.php @@ -0,0 +1,6 @@ + + + + + + + + + diff --git a/app/code/Kai/Product/view/frontend/layout/catalog_product_view.xml b/app/code/Kai/Product/view/frontend/layout/catalog_product_view.xml new file mode 100755 index 00000000..9d48b576 --- /dev/null +++ b/app/code/Kai/Product/view/frontend/layout/catalog_product_view.xml @@ -0,0 +1,20 @@ + + + + + + + + 🛒🛒 Kai Tab + + + + + + + + + + + + diff --git a/app/code/Kai/Product/view/frontend/layout/module_index_index.xml b/app/code/Kai/Product/view/frontend/layout/module_index_index.xml new file mode 100755 index 00000000..d04a9a47 --- /dev/null +++ b/app/code/Kai/Product/view/frontend/layout/module_index_index.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/app/code/Kai/Product/view/frontend/templates/product/view/custom_attribute.phtml b/app/code/Kai/Product/view/frontend/templates/product/view/custom_attribute.phtml new file mode 100755 index 00000000..de883fc7 --- /dev/null +++ b/app/code/Kai/Product/view/frontend/templates/product/view/custom_attribute.phtml @@ -0,0 +1,7 @@ + +getCustomAttribute()): ?> +
+ escapeHtml(__('Custom Attribute Label hello')) ?>: + escapeHtml($block->getCustomAttribute()) ?> +
+ diff --git a/app/code/Kai/Product/view/frontend/templates/product/view/custom_tab.phtml b/app/code/Kai/Product/view/frontend/templates/product/view/custom_tab.phtml new file mode 100755 index 00000000..3be6c6b2 --- /dev/null +++ b/app/code/Kai/Product/view/frontend/templates/product/view/custom_tab.phtml @@ -0,0 +1,22 @@ +headerHTML() ?> + +
+
+
+ + <?= $block->getProduct()->getName() ?> + +
+
+

getProduct()->getName() ?>

+

getCustomAttribute() ?>

+
+

getPrice() ?>

+
+ +
+
+
diff --git a/app/code/Kai/Product/view/frontend/templates/product/view/header.phtml b/app/code/Kai/Product/view/frontend/templates/product/view/header.phtml new file mode 100755 index 00000000..878ddf55 --- /dev/null +++ b/app/code/Kai/Product/view/frontend/templates/product/view/header.phtml @@ -0,0 +1,148 @@ + diff --git a/app/code/Kai/Product/view/frontend/templates/sample.phtml b/app/code/Kai/Product/view/frontend/templates/sample.phtml new file mode 100755 index 00000000..e7175a5d --- /dev/null +++ b/app/code/Kai/Product/view/frontend/templates/sample.phtml @@ -0,0 +1 @@ +

Hello Product by Kai!

diff --git a/app/code/Kai/Widget/Block/Widget/MyWidget.php b/app/code/Kai/Widget/Block/Widget/MyWidget.php new file mode 100755 index 00000000..cdcf440b --- /dev/null +++ b/app/code/Kai/Widget/Block/Widget/MyWidget.php @@ -0,0 +1,10 @@ + + + + diff --git a/app/code/Kai/Widget/etc/widget.xml b/app/code/Kai/Widget/etc/widget.xml new file mode 100755 index 00000000..3000a4e1 --- /dev/null +++ b/app/code/Kai/Widget/etc/widget.xml @@ -0,0 +1,13 @@ + + + + + Add widget. + + + + Description of the parameter 1. + + + + diff --git a/app/code/Kai/Widget/registration.php b/app/code/Kai/Widget/registration.php new file mode 100755 index 00000000..457d2521 --- /dev/null +++ b/app/code/Kai/Widget/registration.php @@ -0,0 +1,6 @@ + + +

Kai Widget Hello, I am a custom widget!

+ diff --git a/app/code/Kai/Widget/view/layout/my_module_index_index.xml b/app/code/Kai/Widget/view/layout/my_module_index_index.xml new file mode 100755 index 00000000..14ad8afd --- /dev/null +++ b/app/code/Kai/Widget/view/layout/my_module_index_index.xml @@ -0,0 +1,11 @@ + + + + + + vendor_module_mywidget + + + + +