I want create new table out of magento, in interface, without inheriting setup class. I tried to get resource model of setup. This didn't work:
require_once 'app/Mage.php';
Mage::init();
$setup = Mage::getResourceModel('catalog/setup');
I was also thinking about Mage::getResourceModel('core/resource_setup') but i have an error: Fatal error: Call to a member function startSetup() on a non-object in C:\xampp\
htdocs\LPP_MAGENTO_EE_CUSTOM\app\code\core\Mage\Core\Model\Resource\Setup.php on
line 944
Do you have any idea?
(I saw this question but it doesn't work for me)
I did it with $setup = Mage::getModel('eav/entity_setup', 'core_setup') example for create new attribute for Category within my code:
require_once 'app/Mage.php';
Mage::init();
$setup = Mage::getModel('eav/entity_setup', 'core_setup');
$setup->addAttribute('catalog_category', 'xxx', array(
...
));
Related
I have checked in magento soap API but I can not find API for add product to wish list so I am developing own API but I don't know what is the problem with my code so please help me to find solution.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once '../app/Mage.php';
Mage::app();
$customer_id = $_GET['customer_id'];
$product_id = $_GET['product_id'];
$customer = Mage::getModel('customer/customer');
$wishlist = Mage::getModel('wishlist/wishlist');
$product = Mage::getModel('catalog/product');
$customer->load($customer_id);
$wishlist->loadByCustomer($customer_id);
$res = $wishlist->addNewItem($product->load($product_id));
if($res)
{
$status =1;
$message = "your product has been added in wishlist";
}
else
{
$status =0;
$message = "wrong data send";
}
$result = array("status" =>$status,"message"=>$message);
header('Content-type: application/json; charset=utf-8');
echo json_encode($result);
?>
There is a similar question you might want to check.
In your code you are not extending Magento API in any way but creating a standalone hackish script that inserts items to wishlist. I suggest that you take a look on how to develop a magento extension or if you need to create a backend (CLI) script, at least use the same structure as in shell/abstract.php and extend the shell base class - you will save yourself loads of headaches.
Moreover, your code is not secure, maintainable and removes all the benefits of using Magento as an ecommerce platform/framework (security, authorization & authentication etc)
Inchoo have quite some blog posts that could give you an idea where to begin
http://inchoo.net/magento/magento-api-v2/
http://inchoo.net/magento/extending-the-magento-api/
/* error_reporting(E_ALL);
ini_set("display_errors", 1);*/
You Have Comment This line And Write this
require_once './app/Mage.php';
I want to access function of controller of Adminhtml from outside. I have tried using:
$mageFilename = '../app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app();
if(!class_exists('IWD_OrderManager_Adminhtml_Sales_OrderrController'))
{
require_once('IWD_OrderManager_Adminhtml_Sales_OrderrController.php');
}
$controller = new IWD_OrderManager_Adminhtml_Sales_OrderrController(
Mage::app()->getRequest(),
Mage::app()->getResponse()
);
$request = $controller->getRequest();
$response = $controller->getResponse();
$controller->blockdatesAction();
but it is not working.
It works using :
file_get_contents('http://url.com/[...]/controller/action/');
but it gives error:
{"ajaxExpired":1,"ajaxRedirect":"http:\/\/www.url.com\/index.php\/admin\/admin\/index\/login\/key\/b91e3bd674dd138b7ea5856117d59e20\/"}
I think it is because Adminhtml functions are not allowed access without login.
Is this something that I can achieve (even by making changes in core files for this case)?
Thanks in Advance.
Trying to access the magento cart from an external php file, I have loaded Mage and am able to access products & categories but for some reason I'm unable to access the cart information.
Shop is located in www.domain.com/shop/
PHP File is located in www.domain.com/file.php
Magento cookie setting is set to '/'
I have looked at and tried many example of how to get the information and none of them have worked, the code I have at the moment is:
<?php
require_once '/home/admin/public_html/shop/appMage.php';
Mage::app();
Mage::getSingleton('checkout/cart', array('name' => 'frontend'));
$cartItemsCount = Mage::getSingleton('checkout/cart')->getItemsCount();
$cartTotal = Mage::helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal());
echo 'You have '. $cartItemsCount . ' item(s) in your cart. <a class="cartgo" href="'.Mage::helper('checkout/cart')->getCartUrl().'">Checkout</a>';
if($cartTotal > 0){ echo '<span>[£'.$cartTotal.']</span>'; }
echo '</a>';
?>
It works perfectly fine within the magento site but not from this external file for some reason. It returns a 0 even though there is a product in the cart.
Any pointers?
Try
// Mage init
require_once '../../app/Mage.php';
umask(0);
Mage::init('default');
Mage::getSingleton('core/session', array('name' => 'frontend'));
// Get customer session
$session = Mage::getSingleton('customer/session');
// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
$cartItemsCount = $cart->getItemsCount();
see magento 1.8 add product to cart using php
I had use a code in joomla 1.5 to laod mod_related_items in com_content >> article:
<?php
jimport('joomla.application.module.helper');
$module = &JModuleHelper::getModule('module_type(example:"mod_related_items")','Position-name');
echo JModuleHelper::renderModule($module);
?>
<?php echo $this->item->event->afterDisplayContent; ?>
I had use this code end of this file: components/com_content/views/article/tmpl/default.php
now i want use this code in joomla 2.5.
when i used it in jooma 2.5, I had these errors:
Notice: Trying to get property of non-object in
C:\wamp\www\kknews.ir\libraries\joomla\application\module\helper.php
on line 152
Notice: Trying to get property of non-object in
C:\wamp\www\kknews.ir\libraries\joomla\application\module\helper.php
on line 156
Notice: Trying to get property of non-object in
C:\wamp\www\kknews.ir\libraries\joomla\application\module\helper.php
on line 159
Notice: Undefined property: stdClass::$content in
C:\wamp\www\kknews.ir\templates\system\html\modules.php on line 16
please help me.
Try this,
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$Module = JModuleHelper::getModule('mod_fmDataGrid');
$Params = "param1=bruno\n\rparam2=chris";//If any params
$Module->params = $Params;//If any params
echo $renderer->render($Module);
Hope it works..
is it possible to render Joomla content from external script? For example I have some html string, which I want to pass to com_content component, to make all content plugin and module features available. I think I should use JDocumentRendererComponent class. Code in my external file:
<?php
require_once ('framework.php'); //loading joomla framework
jimport('joomla.document.html.renderer.component');
$contentHtml = '<p>Some content html</p>';
echo JDocumentRendererComponent::render('com_content',array(),$contentHtml);
?>
What I get is error on the last line:
Fatal error: Class 'JDocumentRendererComponent' not found...
What Im doing wrong? Any ideas?
It's because you haven't included the Joomla framework to the external script. Use the below code. This will ensure that the Joomla! environment is loaded correctly
/* Initialize Joomla framework */
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
/* Required Files */
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/* To use Joomla's Database Class */
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
/**************************************************/
// Your code starts here...
// Remember that the Site application isn't running, so you cannot access $mainframe or any of its methods.
/**************************************************/
JDocumentRendererComponent Class is located in located in /libraries/joomla/document/html/renderer/component.php if you correct load the framework everything should work fine.
I found other solution for my question. The job can be also done by content plugin events (triggers). The piece of code from components/com_content/views/article/view.html.php:
JPluginHelper::importPlugin('content');
$results = $dispatcher->trigger('onContentPrepare', array ('com_content.article', &$item, &$this->params, $offset));
$item->event = new stdClass();
$results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$item, &$this->params, $offset));
$item->event->afterDisplayTitle = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$this->params, $offset));
$item->event->beforeDisplayContent = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$this->params, $offset));
$item->event->afterDisplayContent = trim(implode("\n", $results));
So we can actually make an object from our string and pass it to these triggers. As a result we are getting content rendered like an article, with its major functionality.
Some more info about it:
http://www.inmotionhosting.com/support/edu/joomla-25/create-plugin/content-plugin-events
https://groups.google.com/forum/#!msg/joomla-dev-cms/VZVurjiZWIs/9Vr45KS2LTMJ