Oct
24
2009
Tested on:
SingleFeed Export Module v1.1.0
Magento v1.3.2.4
So I found this great module for Magento the other day, made by SingleFeed. It will export a product data feed every night. Then, we can import this feed into things like Google Base.
I ran into a problem though. You can’t import a data feed into Google Base that contains HTML tags and special characters. Most of the clients I work with prefer to have a WYSIWYG editor for things like the CMS pages, product descriptions, etc., which will add HTML formatting in the database. The SingleFeed Export Module does not automatically strip HTML on the fly (however I believe if you sign-up for an account at their website, they have a wizard that can do it for you.)
I poked around at the code for a bit and discovered that stripping the HTML tags and special chars would be quite easy using two functions: strip_tags, htmlspecialchars_decode.
Open app/code/community/SingleFeed/Export/Model/Mysql4/Profile.php and goto line 360:
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
| // format product data as needed
foreach ($products as $id=>&$p) {
foreach ($p as $attr=>&$value) {
// replace raw numeric values with source option labels
if ($options = $this->attr($attr, 'options')) {
if (is_array($value)) {
foreach ($value as &$v) {
$v = isset($options[$v]) ? $options[$v] : '';
}
} else {
$value = isset($options[$value]) ? $options[$value] : '';
}
}
// combine multiselect values
if (is_array($value)) {
$value = join(', ', $value);
}
// process special cases of loaded attributes
switch ($attr) {
// product url
case 'url_path':
$p["singlefeed.url"] = $baseUrl.$value;
break; |
I love well-written code, especially with good comments. All we’re going to do is add in our new formatting (in this case, just for the product description.)
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
| // format product data as needed
foreach ($products as $id=>&$p) {
foreach ($p as $attr=>&$value) {
// replace raw numeric values with source option labels
if ($options = $this->attr($attr, 'options')) {
if (is_array($value)) {
foreach ($value as &$v) {
$v = isset($options[$v]) ? $options[$v] : '';
}
} else {
$value = isset($options[$value]) ? $options[$value] : '';
}
}
// combine multiselect values
if (is_array($value)) {
$value = join(', ', $value);
}
// process special cases of loaded attributes
switch ($attr) {
// product url
case 'url_path':
$p["singlefeed.url"] = $baseUrl.$value;
break;
// product descriptions
case 'description':
$p["description"] = htmlspecialchars_decode(strip_tags($value));
break; |
That was almost a little too easy…
2 comments | tags: data feed, google base | posted in Magento
Jan
16
2009
I’m surprised there is not one in the default template for Magento. Nevertheless, it’s pretty common to see a login box on a sidebar, and I need one. This is actually pretty simple to do, we’re going to be modifying templates, layouts, and unfortunatly we’re going to have to alter the core (for something really silly.)
First, lets go ahead and make a template for the mini login box. Take a look in ⁄template⁄customer⁄form⁄… What’s this!? We already see that there is a mini.login.phtml. For a closer look:
<form action="<?php echo $this->getPostActionUrl() ?>" method="post">
<table width="100%" class="mini-login">
<tr><td><?php echo $this->__('Email') ?>:</td><td><input name="login[username]" /></td></tr>
<tr><td><?php echo $this->__('Password') ?>:</td><td><input name="login[password]" /></td></tr>
<tr><td> </td><td><input type="submit" value="<?php echo $this->__('Login') ?>" /></td></tr>
</table>
</form>
We’ll, even though functional, this isn’t styled nor does it fit in with the default Magento template. So let’s change this.
<div class="box base-mini mini-login-form">
<div class="head">
<h4><?php echo $this->__('Login') ?></h4>
</div>
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
<div class="content">
<ul class="form-list">
<li>
<label for="email"><?php echo $this->__('Email Address') ?> <span class="required">*</span></label><br />
<input name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" title="<?php echo $this->__('Email Address') ?>" id="email" type="text" class="input-text required-entry" style="width:122px;" />
</li>
<li>
<label for="pass"><?php echo $this->__('Password') ?> <span class="required">*</span></label><br />
<input name="login[password]" type="password" class="input-text required-entry validate-password" id="pass" style="width:122px;" />
</li>
</ul>
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
</div>
<div class="actions">
<button class="form-button-alt" type="submit" name="send" id="send2"><span><?php echo $this->__('Login') ?></span></button>
</div>
</form>
<script type="text/javascript">
var dataForm = new VarienForm('login-form', true);
</script>
</div>
Also add this to your CSS:
.mini-login-form h4 { background-image:url(../images/icon_page_white_text.gif); }
Now that we have a template (mini.login.phtml), we’re going to have to add it to our block structure. Open layout/customer.xml, and make this change starting at line 65.
<customer_logged_out>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>Log In</label><url helper="customer/getLoginUrl"/><title>Log In</title><prepare/><urlParams/><position>100</position></action>
</reference>
<remove name="wishlist_sidebar"></remove>
<remove name="reorder"></remove>
<reference name="right">
<block type="customer/form_login" name="mini_login" template="customer/form/mini.login.phtml" />
</reference>
</customer_logged_out>
Remember to copy this file/folder structure and put it in app/code/local. We do this, because when you go to upgrade your Magento installation, your core files get patched, thus erasing all the hard work you did
13 comments | tags: login box, mini-login | posted in Magento, Snippet
Recent Comments