Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Webinar for X-Cart 5 developers on March,18th.

 
Reply
   X-Cart forums > News and Announcements
 
Thread Tools
  #41  
Old 04-07-2014, 03:59 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Webinar for X-Cart 5 developers on March,18th.

Happy to hear that you solved the problem with translation.

You fix basically meant that News model is now extends an abstract model that allows translation (i18n) and as soon as you create the NewsTranslation model, X-Cart 5 automatically creates the utility columns like id, so you only need to specify meaningful part: what field types to use for title and body columns.

As for your question about why use AEntity at all, many models does not need translations. Classic example is Inventory. There is simply nothing to translate, so using AEntity here saves your time because you do not need InventoryTranslation class. Also, you do not create excessive tables in your database.

You can check XLite/Model folder for more examples of models that created based on AEntity.

Finally, I am pretty happy that you are asking questions and I am even more happy to help you learn X-Cart 5 through your questions.

I am sorry, I cannot reply straight away, because of big amount of work at the moment, but I will do my best to answer on forums as quick as possible, so please keep asking with no hesitation : )

Tony.

Quote:
Originally Posted by totaltec
Thanks Ksenia!

Tony,
I solved the problem (thankfully I was stuck for hours!), but I would still like an explanation of why this works. I found that by modifying XLite\Module\Tony\News\Model\News.php and changing the line:
Code:
class News extends \XLite\Model\AEntity
To:
Code:
class News extends \XLite\Model\Base\I18n
Fixes the error that it was throwing, and the table "xc_news_translations" is successfully created. The functioning of the module appears unchanged besides that.

What is the difference here, and why should we ever use "\XLite\Model\AEntity" if it cannot be translated?
Reply With Quote

The following 2 users thank tony_sologubov for this useful post:
nhat (04-18-2014), totaltec (04-07-2014)
  #42  
Old 04-08-2014, 12:18 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Webinar for X-Cart 5 developers on March,18th.

Tony,
First let me say thank you, it is very encouraging having your help during this process.

I am developing a new module, for a drop down menu system. This module is only affecting the admin side at the moment. I have a root level menu, with sub-menu items. Similar to categories and subcategories but less complicated. I need to know how to query the database, and retrieve the name of the root level category based on its id. Simple, I know!

Here is a brief video outlining the challenge: http://youtu.be/fUN8WpSHnE4

Module is attached, I renamed the tar file to zip so it would upload. Thanks in advance Tony, I hope to hear from you soon.
Attached Files
File Type: zip Baby-DropDown-v5_0_0.zip (67.0 KB, 2 views)
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #43  
Old 04-09-2014, 06:04 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Webinar for X-Cart 5 developers on March,18th.

Tony,
I have made some progress on this issue, I edited XLite\Module\Baby\DropDown\Controller\Admin and added this code:
Code:
/** * Get parent name * * @return string */ public function getParentName() { $parent_id = $this->getParent_Id(); $parent = \XLite\Core\Database::getRepo('\XLite\Module\Baby\DropDown\Model\DropDown')->findOneById($parent_id); $parentName = $parent->name; return $parentName; }
At least now I can echo the name to myself, I need to figure out how best to use it in the template next.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #44  
Old 04-10-2014, 10:47 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Webinar for X-Cart 5 developers on March,18th.

Hi Mike!

Sorry for being silent for a while.

1) The following test script will show you how you can get the category name by ID:

PHP Code:
<?php

require_once 'top.inc.php';

$category = \XLite\Core\Database::getRepo('\XLite\Model\Category')->find(2);

echo 
$category->getName();

This code must be put into PHP script in the root folder of X-Cart 5. You can see the whole process here. We are pulling a category object from repository and then calling getName() out of it to get name. You can call methods get<PROPERTY NAME> to any property of the object like getId(), getBody() and so on.

These getters are added automatically during cache rebuild process and you do not have to create them manually.

2) If you define the method that returns the category object in the controller and call it getDropDownObject, then you can output its name in your template as:

{getDropDownObject.name}

or

{getDropDownObject.getName()} if you want to call as a method of this object

or

{getDropDownObject.getName():h} if you want to allow HTML tags.

Please, let me know if it helps.

Tony.

Quote:
Originally Posted by totaltec
Tony,
I have made some progress on this issue, I edited XLite\Module\Baby\DropDown\Controller\Admin and added this code:
Code:
/** * Get parent name * * @return string */ public function getParentName() { $parent_id = $this->getParent_Id(); $parent = \XLite\Core\Database::getRepo('\XLite\Module\Baby\DropDown\Model\DropDown')->findOneById($parent_id); $parentName = $parent->name; return $parentName; }
At least now I can echo the name to myself, I need to figure out how best to use it in the template next.
Reply With Quote

The following user thanks tony_sologubov for this useful post:
nhat (04-15-2014)
Reply
   X-Cart forums > News and Announcements


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:52 AM.

   

 
X-Cart forums © 2001-2020