Magento网店自定义模板初探(1)——文件夹结构

Magento是个很强大的php网店建站系统。它将模块与结构皮肤分离得相当清晰,为建站提供很大的灵活性和定制性。但是这点也造成了它上手困难的缺陷。可以说不看相关文档会觉得一头雾水,除了CSS根本不知道上哪里去改HTML结构和修改模块的位置。我使用的是1.6.2.0版。

官方模板设计说明文档:Magento Designer's Guide 下载>>>

官方的这份文档并不是那么容易阅读,我还参考了一下《制作你自己的Magento主题》一文。

不过此文虽好,已是03年前的东西。Magento在后台的管理以及一些文件结构上都有些变化,你可能照着此文去做的话,找不到你想要的东西。但是作为辅助理解官方文档的资料还是相当不错的。

好了,下面以我的理解来诠释一下。

用到的文件结构

官方文档上花了很大篇幅来介绍其文件夹结构,可见理解它是多么重要。不过我觉得丫说得忒繁琐了点。。。

作为一个前端设计者,我们会用到的只有一下两个文件夹(其他的都不用你管):

  • \app\design\frontend\
    所有的Module结构逻辑和布局逻辑都在这个文件夹里面哦!
  • \skin\frontend\
    你的CSS和CSS用到的图片都在这里哦!

好,我们再来细细分析这两个文件夹中的子文件夹的作用。

  • \app\design\frontend
    • \base
      存放构成系统最基础的结构。该文件夹的内容极其重要,不能修改和删除。这点会在后面有更详细的说明。
      • \base\default\etc 这个文件夹目前还没搞清楚到底作何用处。。。里面只有一个widget.xml
      • \base\default\layout 用xml文件来存放页面的布局
      • \base\default\template 所有module的HTML和内部逻辑都被单独抽离出来以单独的文件夹分别存放
    • \default
      系统默认使用的主题结构。默认包含blank/default/iphone/modern四个主题。
      • \default\default(iphone, modern, or etc.)\locale 用于替换网站的语言版本
  • \skin\frontend
    • \base
      同上,是存放构成系统最基础的CSS样式。该文件夹的内容极其重要,不能修改和删除。这点会在后面有更详细的说明。
      • \base\default\css 存放CSS样式
      • \base\default\images 存放CSS内使用的图片
      • \base\default\js 存放javascript文件
    • \default
      系统默认使用的主题样式。默认包含blank/default/iphone/modern/blue/french/german四个主题。内部结构跟base文件夹类似。

可以看到,这两个文件夹内的文件结构很相似,名称几乎都是一样的,但是不要因此认为它们是有对应关系的。这点在官方文档中重点强调了。它们之间没有对应的关系。

skin文件夹的结构同ASP.NET的App_Theme主题文件夹一样。另外,enterprise版本和communite版本的Magento的文件夹结构会稍有不同。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Magento 2中发送多个附件的电子邮件,您需要对`Magento\Framework\Mail\Template\TransportBuilder`类进行扩展。 下面是一个示例代码,它可以让您在Magento 2中发送多个附件的电子邮件: 1. 创建 `Vendor\Module\Model\Mail\Template\TransportBuilder.php` 文件并添加以下代码: ```php <?php namespace Vendor\Module\Model\Mail\Template; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Exception\MailException; use Magento\Framework\Mail\Template\TransportBuilder as MagentoTransportBuilder; use Magento\Framework\Mail\TransportInterfaceFactory; use Magento\Framework\Translate\Inline\StateInterface; use Magento\Store\Model\StoreManagerInterface; class TransportBuilder extends MagentoTransportBuilder { /** * @var array */ protected $attachments = []; /** * @param array $attachments * @return $this */ public function addMultipleAttachment($attachments = []) { foreach ($attachments as $attachment) { if (file_exists($attachment['path'])) { $this->attachments[] = [ 'type' => $attachment['type'], 'name' => $attachment['name'], 'path' => $attachment['path'] ]; } } return $this; } /** * @param null|string|array $to * @param array $templateVars * @param null|string $templateOptions * @param null|string $transportOptions * * @throws MailException * * @return TransportInterfaceFactory */ public function getTransport( $to = null, array $templateVars = [], $templateOptions = null, $transportOptions = null ) { if (!empty($this->attachments)) { foreach ($this->attachments as $attachment) { $this->message->createAttachment( file_get_contents($attachment['path']), $attachment['type'], \Zend_Mime::DISPOSITION_ATTACHMENT, \Zend_Mime::ENCODING_BASE64, $attachment['name'] ); } } return parent::getTransport($to, $templateVars, $templateOptions, $transportOptions); } } ``` 2. 创建 `Vendor_Module` 模块的 `di.xml` 文件并添加以下代码: ```xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Framework\Mail\Template\TransportBuilder" type="Vendor\Module\Model\Mail\Template\TransportBuilder" /> </config> ``` 3. 在您的模块中使用以下代码发送多个附件的电子邮件: ```php <?php namespace Vendor\Module\Controller\Index; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Framework\Translate\Inline\StateInterface; use Magento\Store\Model\StoreManagerInterface; class SendEmail extends Action { /** * @var TransportBuilder */ protected $transportBuilder; /** * @var StateInterface */ protected $inlineTranslation; /** * @var StoreManagerInterface */ protected $storeManager; /** * @param Context $context * @param TransportBuilder $transportBuilder * @param StateInterface $inlineTranslation * @param StoreManagerInterface $storeManager */ public function __construct( Context $context, TransportBuilder $transportBuilder, StateInterface $inlineTranslation, StoreManagerInterface $storeManager ) { $this->transportBuilder = $transportBuilder; $this->inlineTranslation = $inlineTranslation; $this->storeManager = $storeManager; parent::__construct($context); } /** * @return void */ public function execute() { $attachmentOne = [ 'name' => 'Attachment One', 'path' => 'path/to/attachment/one.pdf', 'type' => 'application/pdf' ]; $attachmentTwo = [ 'name' => 'Attachment Two', 'path' => 'path/to/attachment/two.pdf', 'type' => 'application/pdf' ]; try { $this->inlineTranslation->suspend(); $this->transportBuilder->setTemplateIdentifier('your_email_template_id') ->setTemplateOptions([ 'area' => 'frontend', 'store' => $this->storeManager->getStore()->getId() ]) ->setTemplateVars([]) ->setFrom([ 'email' => 'sender@example.com', 'name' => 'Sender Name' ]) ->addTo('recipient@example.com', 'Recipient Name') ->addMultipleAttachment([$attachmentOne, $attachmentTwo]) ->getTransport() ->sendMessage(); $this->inlineTranslation->resume(); $this->messageManager->addSuccess(__('Your email was sent successfully.')); } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError(__('There was an error sending your email. Please try again later.')); } return $this->_redirect('*/*/index'); } } ``` 以上代码将会发送带有两个附件的电子邮件。您可以根据自己的需要更改附件的数量和详细信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值