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

Create a new table in XC database?

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 07-11-2016, 09:03 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 446
 

Default Create a new table in XC database?

Is it possible to create a new table in XC database?

The reason that I am asking this is as follows. I am trying to write
a gateway module for Payplug. The way it should work, in my idea, would be

i) I am more or less following Tony's demo payment module schema
(http://kb.x-cart.com/display/XDD/Creating+a+payment+method) so that
the checkout page sends the customer to a page called "payment.php"
ii) payment.php makes a call to API, so that the customer is taken to
Payplug's payment page.
iii) It looks like it is impossible to include the payment status in the return URL
so, I need yet another page that will process the payment status, let's say,
response.php
iv) customer are then taken to an appropriate page in Xcart.

Now, the Payplug API creates a payment, then attributes a payment_id to it.
To retrieve the payment status information, we need this payment_id. And,
we need the return URL to create the payment, it is impossible to pass this variable from payment.php to response.php by adding its value using GET method. On the other hand, the X-cart's transaction ID is created before
the payment object, so we can pass it from payment.php to response.php.

So the question is, how do we get the payment id assigned by API in the page
payment.php from the transaction ID in response.php? One way to deal with this would be to create a table with two columns transaction ID and payment ID. But this requires creating a table and accessing to it. As these pages, payment.php and response.php are not really part of modules, I guess I can put
whatever codes I want there, but would creating a new table cause problem for
re-deploying the site/updating?

Thank you in advance.
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
  #2  
Old 07-11-2016, 02:10 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

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

Default Re: Create a new table in XC database?

Quote:
Originally Posted by Ed B.
Is it possible to create a new table in XC database?

Absolutely. This is done by adding a Model into your Module.

Make a file in your module:
XLite\Module\YourDevID\YourModuleName\Model\Table. php

Code:
namespace XLite\Module\YourDevID\YourModuleName\Model; /** * @Entity * @Table (name="devid_some_table") */ class Table extends \XLite\Model\AEntity { /** * @Id * @GeneratedValue (strategy="AUTO") * @Column (type="integer", options={ "unsigned": true }) */ protected $id; /** * @Column (type="boolean") */ protected $enabled = true; /** * @Column (type="string", length=1024) */ protected $text = ''; }

Of course you can rename the Table.php class to reflect something more relevant to your cause, and change the field names to your liking.

This file above should create a table called "devid_some_table", which you can see in the comments and can change to your liking.
__________________
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

The following 2 users thank totaltec for this useful post:
Ed B. (07-13-2016), qualiteam (07-12-2016)
  #3  
Old 05-05-2017, 02:14 PM
 
Bryce Bryce is offline
 

Newbie
  
Join Date: Apr 2017
Posts: 7
 

Default Re: Create a new table in XC database?

I would advise against creating a table within the MySQL database used for XCart, as I have noticed that the tables I'd created on my own have been deleted during the last two minor updates of XCart modules (and basic updates of the XCart platform itself).

Instead, I recommend creating a new database just for your new table, and have the database user have read/write permissions, just like it would have for the XCart database.

For queries that involve both databases, just add the database name prior to the table name, such as...

SELECT * FROM `xcart_database`.`xcart_table`, `custom_database`.`custom_table` WHERE `xcart_database`.`xcart_table`.`unique_id` = `custom_database`.`custom_table`.`xcart_unique_id`
__________________
Bryce
X-Cart Business v5.3.2.8
81 Modules: 2Checkout.com, Amazon Pay, Amazon S3 Images, AuctionInc ShippingCalc, Authorize.Net SIM, Barclaycard ePDQ e-Commersce, Bestsellers, Bulk Editing, Canada Post, CloudSearch & CloudFilters, Concierge, Contact us, Coupons, Crisp White skin, Custom Order Statuses, E-goods, Fast Lane Checkout, Featured Products, FedEx, File attachments, Flyout Categories Menu, Free Shiping and Shipping freights, Froala WYSIWYG editor integration, Geolocation, Go Social, Google Analytics, iDEAL Payments, Ingenico Payment Services (Ogone), JSON API, MailChimp Integration with E-commerce support, Market price, Moneris (eSELECTplus-
Hosted Pay Page), Multicurrency, Newsletter subscriptions, Not Finished Orders, Order messages (Beta), PayPal, PayPal Here, Previous and Next Product, Product Advisor, Product Filter, Product reviews, Product Tags, QR Code generator, QuantumGateway, Related Products, REST API, Sage Pay (Form), Sale, Sales Tax, Segment Integration, ShipStation, Simple CMS, Site Map, Skrill, Social Login, Special Offers (base), Stripe, Theme tweaker, Translation: British English, Translation: Chinese, Translation: Dutch, Translation: French, Translation: German, Translation: Russian, U.S.P.S., UPC/ISBN and Mfn#/Vendor# fields, Update Inventory, UPS, User permissions, Wholesale, Wordpress Integration, X-Cart Mobile Admin, X-Payments connector, XML sitemap
Reply With Quote
  #4  
Old 05-09-2017, 11:12 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Create a new table in XC database?

Quote:
Originally Posted by Bryce
I would advise against creating a table within the MySQL database used for XCart

Although this may (in some cases) make sense for X-Cart 4, in X-Cart 5 there are no reasons to create a separate database for new tables.

If you follow the X-Cart 5 coding guidelines and create new tables by adding new Model classes to your module, the tables won't be gone with the next update/upgrade/redeploy.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #5  
Old 05-10-2017, 07:21 AM
 
Bryce Bryce is offline
 

Newbie
  
Join Date: Apr 2017
Posts: 7
 

Default Re: Create a new table in XC database?

Hi Alex,

I disagree with a subjective response (Why) to an objective question (How).

In my particular case, I use it as a method of connecting two databases. When a password is changed on our main website, then it is also modified for the shopping cart login (for purchasing materials related to the topic, such as books or conference recordings).

Would you like to make a reference to the coding guidelines documentation that you are referring to?

Google search:
[url]https://www.google.com/search?q=X-Cart 5 coding guidelines and create new tables by adding new Model classes to your module
Reply With Quote
  #6  
Old 05-10-2017, 09:14 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Create a new table in XC database?

OK, there may be reasons to keep custom tables in a separate MySQL database. However, for most cases you are to create custom X-Cart 5 tables by declaring new Model classes - this will guarantee that X-Cart 5 knows about these tables and can use in its routines and functions.

I mean this documentation for developers:
http://devs.x-cart.com/en/basics/understanding_models.html
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote

The following user thanks qualiteam for this useful post:
dagdag (04-23-2020)
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may 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:46 AM.

   

 
X-Cart forums © 2001-2020