Is there a way to download a full XML schema including headers into a Google Sheet worksheet?
I'm looking to import all elements including the headers from an online XML page into Google Sheets.
The XML page looks like this:
<staff>
<admin>
<first-name>Patrice</first-name>
<family-name>Withers</family-name>
<year-started>2006</year-started>
<starting-salary>30,500</starting-salary>
<current-salary>34,000</current-salary>
</admin>
<admin>
<first-name>Shelly</first-name>
<family-name>Lancer</family-name>
<year-started>2015</year-started>
<starting-salary>32,500</starting-salary>
<current-salary>33,500</current-salary>
</admin>
</staff>
<students>
<full-time>
<first-name>Henry</first-name>
<family-name>Nunes</family-name>
<status>Freshman</status>
<current-tuition>2,400</current-tuition>
<last-year-tuition>2,200</last-year-tuition>
</full-time>
<part-time>
<first-name>Leslie</first-name>
<family-name>Franks</family-name>
<status>Senior</status>
<current-tuition>2,300</current-tuition>
<last-year-tuition>2,100</last-year-tuition>
</part-time>
</students>
I'm trying to have Google Sheets download the full XML page, including the element headers, and display it, preferably as above in indented columns, or in a single column to look like this:
<staff>
<admin>
<first-name>Patrice</first-name>
<family-name>Withers</family-name>
<year-started>2006</year-started>
<starting-salary>30,500</starting-salary>
<current-salary>34,000</current-salary>
</admin>
<admin>
<first-name>Shelly</first-name>
<family-name>Lancer</family-name>
<year-started>2015</year-started>
<starting-salary>32,500</starting-salary>
<current-salary>33,500</current-salary>
</admin>
</staff>
<students>
<full-time>
<first-name>Henry</first-name>
<family-name>Nunes</family-name>
<status>Freshman</status>
<current-tuition>2,400</current-tuition>
<last-year-tuition>2,200</last-year-tuition>
</full-time>
<part-time>
<first-name>Leslie</first-name>
<family-name>Franks</family-name>
<status>Senior</status>
<current-tuition>2,300</current-tuition>
<last-year-tuition>2,100</last-year-tuition>
</students>
IMPORTDATA, as another user was advised with a similar question here, failed because some of the XML data have commas, similar to the sample output above.
if the url of yours can be scraped from behind authentication credentials you could try:
=ARRAYFORMULA(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
ARRAY_CONSTRAIN(IMPORTDATA("url_here"), 5000, 20)),,999^99))))
also you could perhaps try:
=IMPORTXML("url_here", "//*")
Related
For example:
The url is
index.php/catalogsearch/advanced/
how to find out which module it belongs to ? In this case I know that the frontname is "catalogsearch", the controller is "advanced" and the method is "indexAction" ? But to what module does it belong?
In this case it is easy because the name of the frontname and the name of the module match but if they were different? how can we find the module of the frontname ?
The answer is here, in the config.xml file of the module Mage_CatalogSearch :
<routers>
<catalogsearch>
<use>standard</use>
<args>
<module>Mage_CatalogSearch</module>
<frontName>catalogsearch</frontName>
</args>
</catalogsearch>
</routers>
So I hope you have a good IDE which allows you to perform searches on all files. If you're unable to perform a search, you could edit a template used in the page of the URL you're after, and dump this in a log file :
Mage::app()->getRequest()->getControllerModule();
This will give you "Mage_CatalogSearch". Additionnally, you might want to use these methods too :
Mage::app()->getRequest()->getControllerName();
Mage::app()->getRequest()->getActionName();
//Write below code in index.php file or any phtml files.
/**
* get module name
*/
$this->getRequest()->getModuleName();
More details got through the this link.
I'm trying to figure out the best course of action to change URL keys in the store to be name-sku.html
Currently MAGMI seems to be dictating the url key, which is fine. Some of our products are not imported through MAGMI, so I think I'd probably have to also use the updateurl event to change the url on save -- I found this here for that -- https://magento.stackexchange.com/questions/24869/manufacturer-in-product-url-key
The question is, how is it best to do this within MAGMI? I'm importing about 300,000 products currently. The URL also needs to change, as it currently just uses the default settings.
I've looked into the wiki here -- http://wiki.magmi.org/index.php?title=Value_Replacer -- I guess the following code could work for the way it is currently working -- but what do I actually type into the value replacer box?
{{ Slugger::slug({item.name}) }}
Does anyone know how to add the sku to this as well? Would I just do something like....
{{ Slugger::slug({item.name} ."-". {item.sku}) }}
Also, does anyone know if this automatically adds the dashes and the .html?
Any guidance would be extremely appreciated.
EDIT:
I have successfully tested this as working in my test environment, but it is not working as expected in my production environment. I'll go over what happens, and what I did.
1) I purged the core_url_rewrite table
2) I deleted all cache
3) I set up MAGMI (updated it to the most current version as well, and triple checked all my settings)
4) MAGMI went through fine, and the url key on about 5 products that I checked for were how I would expect
5) During the catalog url rewrites reindex, all url keys disappeared.
6) After the reindex was done, they were now in the default magento format (using just the name, and not the sku)
Any ideas?
The only difference between production and development that I can think of at the moment that may have anything to do with this is the fact that I did create a module based on the linked manufacturer-in-product-url-key question on production. Now that I think of it, maybe that's the main difference that I need to address..... I didn't think reindexing would have anything to do with that, but maybe I'm wrong.
Anyway, if anyone has any insight, I would still appreciate it. I have a feeling maybe MAGMI should also be rewriting the url_path?? I think I read something about that somewhere.
Ok, I figured this out. I think this is the best approach.
I was mistaken in my question. I'm actually looking to add the mpn, not the sku. Either way, that doesn't change the process.
So, the best thing to do is to use the Value Replacer in MAGMI, and to create a custom module that updates the url on the Magento catalog_product_save_before event.
Here's exactly what I did.....
MAGMI settings (Value Replacer)
Replaced attributes: url_key
New value for url_key: {{ Slugger::slug({item.name}.' '.{item.mpn}) }}
URLKeyChange (Magento Module)
app/code/local/My/URLKeyChange/etc/config.xml
<config>
<global>
<models>
<LeathornURLRewrite>
<class>Leathorn_URLKeyChange_Model</class>
</LeathornURLRewrite>
</models>
<events>
<catalog_product_save_before>
<observers>
<LeathornURLRewrite>
<type>singleton</type>
<class>LeathornURLRewrite/observer</class>
<method>updateurl</method>
</LeathornURLRewrite>
</observers>
</catalog_product_save_before>
</events>
</global>
</config>
app/code/local/My/URLKeyChange/Model/Observer.php
class My_URLKeyChange_Model_Observer {
public function updateurl($observer){
Mage::log('My log entry', null, 'mylogfile.log');
if($observer->getEvent()->getProduct()){
$Product=$observer->getEvent()->getProduct();
$Url='';
if(!is_null($Product->getData('name'))):
$Url=$Url.$Product->getData('name');
endif;
if(!is_null($Product->getData('mpn'))):
$Url=$Url.$Product->getData('mpn').'-';
endif;
//Mage::log('My log entry'.$Url, null, 'mylogfile.log');
$Product->setData('url_key',$Url);
}
}
}
app/etc/modules/My_URLKeyChange.xml
<config>
<modules>
<My_URLKeyChange>
<!-- Whether our module is active: true or false -->
<active>true</active>
<!-- Which code pool to use: core, community or local -->
<codePool>local</codePool>
</My_URLKeyChange>
</modules>
</config>
URL key will always be just dash separated strings. Don't worry, magento will add .html in it dynamically. You can see in magnento backend in any product configuration page, url key is without html.
Also magento will add dash in url key, Replace your "-" by space " ". Otherwise it will take last word of name and SKU as one word. :)
Let's say I use a custom controller to have a url path/frontend name of
/customcategory
Well, obviously if I have a controller file named 'TestController.php' and indexAction
the url path would be
/customcategory/test/index
What I am trying to figure out is how I do re-name the Test Controller, or modify the config xml file, so I can have a hyphenated url from a controller file such as
/customcategory/test-section/index
I know that if I want /customcategory to be hyphenated, I can just modify the frontend tag in the config file. But the site I am building would benefit from a hyphenated controller route, the part that comes after /customcategory with keywords and I cannot get it to work nor can I find an example on google - as crazy as that may seem.
Thanks for your time.
What you are trying to do is possible using global rewrite in your custom module. You could pass all incoming request for /customcategory/* to a specific controller action. But you would have to manage your own route (base on the depth of your url path).
e.g www.MageIgniter.com/customcategory/path1/path2
config.xml
<global>
<rewrite>
<fancy_url>
<from><![CDATA[/customcategory\/(.*)/]]></from>
<to><![CDATA[customcategory/index/processroute/tagname/$1/]]></to>
<complete>1</complete>
</fancy_url>
<rewrite>
</global>
<frontend>
<routers>
<tagseo>
<use>standard</use>
<args>
<frontName>customcategory</frontName>
</args>
</tagseo>
</routers>
class MageIgniter_Customcategory_IndexController extends Mage_Core_Controller_Front_Action
{
public function processRoute(){
print_r($requestUri = Mage::app()->getRequest()->getRequestUri()); //path1/path2
print_r($this->getRequest()->getParam('tagname')); // path1
print_r($this->getRequest())
// do you custom logic here base on about request path explode('/', trim($requestUri,'/'))
}
...
For a working example see "Product Tags" section # http://www.contempospace.com/bedroom-furniture/wardrobe-closets/custom-closet-systems/isa-closet-system-shelves-hanging-walk-in-reach-in-closet.html
As far as I am aware you cannot add hypens in the url to match up to a filename. If you are trying to get a folder structure you can just add more paths to it.
For example if you wanted:
Namespace/CustomCategory/controller/test/SectionController.php
you could do:
/customcategory/test_section/index
I want to rewrite some of my URLs using a regex. This is my rewrite stuff in config.xml of my module.
<rewrite>
<My_Module>
<from><![CDATA[#^/(abc)|(def)/configuration/#]]></from>
<to>/config/configuration/</to>
<complete>1</complete>
</My_Module>
</rewrite>
As you see, what I am trying to achive is to rewrite all urls that contain abc/configuration or def/configuration. This does not work. So how can I add multiple URLs to the same rewrite in Magento? I dont care if its done with a regex or a line for each rewrite in config.xml, so far I did not manage to figure it out either way.
Thanks!
Addition: I solved this now by using:
<from><![CDATA[#^/.+/configuration/#]]></from>
This did the trick in my case :) ... I am still interested how to solve it the first way though. If anybody knows, please post anyway!
Select first OR second is written like this /(first|second)/
Code bellow is working in 1.8 magento.
$2 will be replaced with what ever (.*) captures.
<config>
<global>
<rewrite>
<My_Module>
<from><![CDATA[#^/(abc|def)/configuration/(.*)#]]></from>
<to><![CDATA[/config/configuration/$2]]></to>
<complete>1</complete>
</My_Module>
</rewrite>
</global>
<config>
I'm developing a custom module for my Magento installation (version 1.6.2.0). I registered a translation file for the module in the config.xml and started to add German translations. The module adds some new behavior to the Magento back end.
While doing the translation I noticed a strange behavior of Magento. Certain words don't get translated by Magento although a translation is provided in the module's csv file.
When I change the key to a different value, the translation works as expected, so Magento seems to see and read the cvs file.
At the moment I notice this behavior for the keys "City" and "Store".
Content of the csv file:
"City","Stadt"
"City1","Stadt"
I use the following line to translate the strings.
Mage::helper('mymodule')->__('City') // returns "City"
When I change the key to "City1" every thing works as expected.
Mage::helper('mymodule')->__('City1') // returns "Stadt"
After this I searched the German translation csv files (provided by the German Magento Community) for a translation for the key "City" and found one in the "adminhtml module".
Mage::helper('adminhtml')->__('City') // returns "Stadt"
So this also works as expected.
I don't know what I'm doing wrong. As I said the same behavior occurs for the string "Store".
Any ideas on this?
Finally I solved the translation problem. The reason was a wrong configuration in the config.xml. I found it out by debugging the code where Magento reads in the translation files. When this happens there's a parameter called scope which is read from one of the XML elements of the config.xml file.
This element should normally have the name of the module, e.g. <MyCompany_MyModule>. In the tutorial I followed to configure the translation, this XML-element was named <translations> which was wrong.
I guess that this might have been correct for an earlier version of Magento. What made it hard to find out was that the errors only occur for keys which were also defined in other modules's translation files. Keys which were only defined in my translation file worked as expected.
An correct configuration should look like this.
<frontend>
...
<translate>
<modules>
<MyCompany_MyModule>
<files>
<default>MyCompany_MyModule.csv</default>
</files>
</MyCompany_MyModule>
</modules>
</translate>
...
</frontend>
<adminhtml>
...
<translate>
<modules>
<MyCompany_MyModule>
<files>
<default>MyCompany_MyModule.csv</default>
</files>
</MyCompany_MyModule>
</modules>
</translate>
...
</adminhtml>
Hard to say without having your code at hand, but my guess would be that the translation scope of your module somehow gets lost (for whatever reason) causing Magento to fallback.
Afaik, in Magento 1.6.2.0 the following translation files also define the key City:
/app/locale/<language>_<region>/Mage_Checkout.csv
/app/locale/<language>_<region>/Mage_Customer.csv
/app/locale/<language>_<region>/Mage_Persistent.csv
/app/locale/<language>_<region>/Mage_Sales.csv
/app/locale/<language>_<region>/Mage_Shipping.csv
/app/locale/<language>_<region>/Mage_XmlConnect.csv
I'd try to change the translation for City in these .csv files one by one, to find out where the translation in question is actually coming from.
Once you found the file to which Magento is falling back, you also know, which translation scope you need to override, to force your translation of City to be used.
For example, if you find changing the translation in Mage_Shipping.csv does take affect, then you edit your translation file (My_Module.csv) to contain
"Mage_Shipping::City","Stadt"