将产品以编程方式分配给Magento中的类别时应使用哪个文件? [英] Which file should I use when assigning products to a category in Magento programatically?

查看:118
本文介绍了将产品以编程方式分配给Magento中的类别时应使用哪个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Magento的新手。我在Magento的后端创建了一个类别。关于如何将产品分配给某个类别的问题很少,但我不明白应该使用哪个文件来使用该代码:



如果我理解正确,那么当您创建类别并为其分配产品时,该页面将由Magento自动生成。我知道有一个 view.phtml 文件,它是网页应该是什么样子的模板。先谢谢你们,伙计们。将等待您的回应。

解决方案

这样的代码示例适用于开发人员(我猜你是主要不是)放入他们自己的模块中,也许作为观察者运行在产品保存事件中。



对于你,我会建议测试这样的小片段文件在您的magento文件夹中。至少在你知道如何创建一个合适的模块之前,这是运行一些自定义代码的最简单方法,也许只需要运行一次。



创建文件 triggerCustomAction.php 在你的Magento根目录下,使它可以从www.yourdomain.com/triggerCustomAction.php访问,运行一次。



以此为起点,您需要在该文件的底部运行代码:

 <?php 

需要'app / Mage.php';
if(!Mage :: isInstalled()){
echo应用程序尚未安装,请先完成安装向导。
出口;
}

Mage :: setIsDeveloperMode(true);
ini_set('display_errors',1);

//这可以从任何商店ID号码改变为这样:
// Mage :: app() - > setCurrentStore(xx);
Mage :: app() - > setCurrentStore(Mage_Core_Model_App :: ADMIN_STORE_ID);

//输入您的代码在这里运行:


I am new to Magento. I have created a category in the back end of Magento. There are quite few threads about how to assign a product to a category, however I don't understand which file should I use to use that code:

If I understand correctly, the page is generated automatically by Magento, when you create a category and assign products to it. I know there is a view.phtml file which is a template of how the webpage should look like. Thank you in advance, guys. Will be waiting for your respond.

解决方案

Code examples like that is for developers (which I'm kind of guessing you're primarily not) to put into their own modules, maybe as an observer running on the product save event.

For you I would instead recommend testing out snippets like that in small freestanding files in your magento-folder. At least until you know how to make a proper module this is the easiest way to run some custom code, that perhaps only needs to run once.

Create file triggerCustomAction.php in your Magento root directory, making it accessible from www.yourdomain.com/triggerCustomAction.php to run it once.

Use this as a starting point, with code you need to run at the bottom of the file:

<?php

require 'app/Mage.php';
if (!Mage::isInstalled()) {
    echo "Application is not installed yet, please complete install wizard first.";
    exit;
}

Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);

// this can be changed from to any store ID number like this:
// Mage::app()->setCurrentStore(xx);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

//enter your code to run below here:

这篇关于将产品以编程方式分配给Magento中的类别时应使用哪个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆