Zend Relationship - Two column referencing single field in other table - zend-framework

I have two tables with structure as mentioned below:
CREATE TABLE `up_offer` (
`up_offer_id` int(11) NOT NULL AUTO_INCREMENT,
`from_subscription_id` int(11) NOT NULL,
`to_subscription_id` int(11) NOT NULL,
PRIMARY KEY (`up_offer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `subscription` (
`subscription_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(1000) NOT NULL,
`code` varchar(45) NOT NULL,
`price` decimal(6,2) NOT NULL,
`billing_cycle` int(11) NOT NULL,
`desc` varchar(2000) DEFAULT NULL,
`start_date` date NOT NULL,
`end_date` date NOT NULL,
`emaillist_id` int(11) NOT NULL,
`old_created_date` datetime NOT NULL,
`old_last_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_on` datetime NOT NULL,
`last_updated_on` datetime NOT NULL,
`is_active` bit(1) NOT NULL DEFAULT b'1',
PRIMARY KEY (`subscription_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The dbTable Class am using for both the tables is as follows:
class Admin_Model_DbTable_Subscription extends Zend_Db_Table_Abstract
{
protected $_name = 'subscription';
protected $_primary = 'subscription_id';
protected $_dependentTables = 'Admin_Model_DbTable_UpOffer';
protected $_referenceMap = array(
'UpOffer' => array(
'columns' => array('subscription_id'),
'refTableClass' => 'Admin_Model_DbTable_UpOffer',
'refColumns' => array('from_subscription_id','to_subscription_id'),
),
);
}
class Admin_Model_DbTable_UpOffer extends Zend_Db_Table_Abstract{
protected $_name = 'up_offer';
protected $_dependentTables = 'Admin_Model_DbTable_Offer';
protected $_referenceMap = array(
'Offer'=>array(
'columns' => 'up_offer_id',
'refTableClass' => 'Admin_Model_DbTable_Offer',
'refColumns' => 'up_offer_id'
)
);
}
I want to get the dependent data from the 'Zend_Db_Table_Row Object':
the code am writing is:
$upOfferData->toArray() gives the fields:
Array
(
[up_offer_id] => 1
[from_subscription_id] => 10
[to_subscription_id] => 9
)
And $upOfferData->findDependentRowset('Admin_Model_DbTable_Subscription'); gives output as follows:
Array
(
[0] => Array
(
[subscription_id] => 10
[name] => 001
[code] => 010
[price] => 10.00
[billing_cycle] => 1
[desc] => Test
[start_date] => 2012-04-21
[end_date] => 2012-05-20
[emaillist_id] => 0
[old_created_date] => 0000-00-00 00:00:00
[old_last_updated] => 2012-04-20 15:29:57
[created_on] => 2012-04-20 09:59:56
[last_updated_on] => 2012-04-20 01:31:44
[is_active] => 1
)
)
What about the to_subscription_id?
How do i correctly map the DbTable Classes and what is the correct way of obtaining the desired out?
The desired should be something like:
Array
(
[0] => Array
(
[subscription_id] => 10
[name] => 001
[code] => 010
[price] => 10.00
[billing_cycle] => 1
[desc] => Test
[start_date] => 2012-04-21
[end_date] => 2012-05-20
[emaillist_id] => 0
[old_created_date] => 0000-00-00 00:00:00
[old_last_updated] => 2012-04-20 15:29:57
[created_on] => 2012-04-20 09:59:56
[last_updated_on] => 2012-04-20 01:31:44
[is_active] => 1
)
[1] => Array
(
[subscription_id] => 9
[name] => 002
[code] => 011
[price] => 50.00
[billing_cycle] => 2
[desc] => Test
[start_date] => 2012-04-21
[end_date] => 2012-05-20
[emaillist_id] => 0
[old_created_date] => 0000-00-00 00:00:00
[old_last_updated] => 2012-04-20 15:29:57
[created_on] => 2012-04-20 09:59:56
[last_updated_on] => 2012-04-20 01:31:44
[is_active] => 1
)
)

Related

Fetch protected data from object zend

I have response and I want to fetch referenceId from it, the response is
Application_Model_User Object
(
[_data:protected] => Array
(
[id] => 2
[email] => test#gmail.com
[password] => ef1dca60798e10a51e3b6201ae7c40fbe2a10887
[salt] => 87fc83906190d1e29b60c5813065af068e16459d
[name] => test
[creationDate] => 2011-07-05
[lastTimeStamp] => 2016-06-03 09:13:53
[enabled] => 1
[loginHash] =>
[employeeNumber] => 0007
[userphoneNumber] => +546546546545
[jobTitle] => Business Manager
)
[_references:protected] => Array
(
[role] => Array
(
[referenceClass] => Application_Model_Role
[referenceId] => 4
[mapperClass] => Application_Model_RoleMapper
[mapper] =>
)
[organisation] => Array
(
[referenceClass] => Application_Model_Organisation
[referenceId] => 1
[mapperClass] => Application_Model_OrganisationMapper
[mapper] =>
)
)
)
How can I fetch ?
In .phtml file in ajax after
success: function(response){
var data = jQuery.parseJSON(response);
for (var i in data)
{
var referenceId = data[i]['referenceId'];
}
}
You can use a getter. You can create a method to return the referenceId.

I'm trying to use Shippo to get a USPS shipping label to send within the US, but can't seem to get any rates to appear

This is my request:
Address from:
Array(
[name] => Mr.John
[street1] => 1234 Market Street
[city] => San Francisco
[zip] => 95432
[state] => CA
[phone] => +1 415 123 1234
[email] => mrjohn+test#gmail.com
[country] => US
[object_purpose] => QUOTE
[company] => Shippo
)
Address to :
Array(
[name] => Ms. Jane
[street1] => 1234 Mission Street
[city] => San Francisco
[zip] => 91234
[state] => CA
[phone] => +1 415 234 2345
[email] => msjane+test#gmail.com
[country] => US
[object_purpose] => QUOTE
[street2] =>
[company] =>
)
Custom Item :
Shippo_Object Object(
[_apiKey:protected] => xxxx
[_values:protected] => Array (
[object_created] => [date]
[object_updated] => [date]
[object_id] => xxxxx
[object_owner] => sender+test#gmail.com
[object_state] => VALID
[description] => IPhone 6
[quantity] => 1
[net_weight] => 3
[mass_unit] => lb
[value_amount] => 450
[value_currency] => USD
[origin_country] => US
[tariff_number] =>
[metadata] => Order ID #123123
)
[_unsavedValues:protected] => Shippo_Util_Set Object (
[_elts:Shippo_Util_Set:private] => Array (
)
)
[_transientValues:protected] => Shippo_Util_Set Object (
[_elts:Shippo_Util_Set:private] => Array (
)
)
[_retrieveOptions:protected] => Array (
)
)
Custom Shipping :
Shippo_Object Object(
[_apiKey:protected] => xxxx
[_values:protected] => Array (
[object_created] => [date]
[object_updated] => [date]
[object_id] => xxxxx
[object_owner] => sender+test#gmail.com
[object_state] => VALID
[certify_signer] => Mr. John
[certify] => 1 [items] => Array (
[0] => xxxx
)
[non_delivery_option] => ABANDON
[contents_type] => MERCHANDISE
[contents_explanation] => IPhone 6
[exporter_reference] =>
[importer_reference] =>
[invoice] => #123123
[commercial_invoice] =>
[license] =>
[certificate] =>
[notes] =>
[eel_pfc] =>
[aes_itn] =>
[disclaimer] =>
[incoterm] =>
[metadata] => Order ID #123123
)
[_unsavedValues:protected] => Shippo_Util_Set Object (
[_elts:Shippo_Util_Set:private] => Array (
)
)
[_transientValues:protected] => Shippo_Util_Set Object (
[_elts:Shippo_Util_Set:private] => Array (
)
)
[_retrieveOptions:protected] => Array (
)
)
Am I miss something? I have address_to, address_from, custom item, and custom shipping all filled out.
I’m from the Shippo team here!
Everything in your call seems good. Please double check that you have your USPS account activated - you can edit it via the Carrier Accounts Endpoint or on the Carriers Page directly.
Since the shipment is domestic, you won’t need to add the “customs item”, nor “customs shipping” information. You should only provide this information when creating an international shipment.
Remove +1 from each phone number, that’s not needed and may cause problems.
Hope that’s helpful.

Illuminate returns results in JSON - why?

I'm using Illuminate to access my database
<body>
<?php
$edges = Edge::all();
foreach ($edges as $key => $value) {
print $value;
}
?>
</body>
browser returns:
{"childID":"A","parentID":"C","updated_at":null,"created_at":null}{"childID":"B","parentID":"E","updated_at":null,"created_at":null}{"childID":"C","parentID":"D","updated_at":null,"created_at":null}{"childID":"C","parentID":"F","updated_at":null,"created_at":null}{"childID":"Y","parentID":"Z","updated_at":"2014-08-07 10:26:54","created_at":"2014-08-07 10:26:54"}
What's odd or unexpected for me at least is that my results are returned in JSON. If you could
shine some light on this, i.e. why this might be, or the reason is...I'd be grateful.
If I dump the results in the browser with:
<?php
print '<pre>';print_r($edges);
?>
produces:
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => Edge Object
(
[connection:protected] =>
[table:protected] =>
[primaryKey:protected] => id
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
)
[original:protected] => Array
(
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
)
[relations:protected] => Array
(
)
[hidden:protected] => Array
(
)
[visible:protected] => Array
(
)
[appends:protected] => Array
(
)
[fillable:protected] => Array
(
)
[guarded:protected] => Array
(
[0] => *
)
[dates:protected] => Array
(
)
[touches:protected] => Array
(
)
[observables:protected] => Array
(
)
[with:protected] => Array
(
)
[morphClass:protected] =>
[exists] => 1
)
[1] => Edge Object
(...)
...
)
In terms of the front-end results - I'm really only interested in the:
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
part of the object; only NOT in JSON; in plain text.

how to apply paypal discount on cart total?

Array
(
[return] => http://www.example.com/
[cancel] => http://www.example.com/
[currency] => EUR
[total] => 38.8
[shipping] => 6
[tax] => 2.85
[itemTotal] => 29.95
[items] => stdClass Object
(
[1] => stdClass Object
(
[quantity] => 1
[name] => Item one
[IDFull] => 1
[priceFull] => 32.8
[tax] => 2.85
[price] => 29.95
[priceWith] => 32.80
[attributes] => Array
(
)
[ID] => 1
)
)
)
This is my sample array for paypal checkout. How to add discount (eg. 20€) on card total price? I have tried many ways, but can't find it out. Thanks!
you can try it as below article
http://chevronscode.com/index.php/paypal-rest-api-add-discount-on-the-total-amount.html
add the discount as an item

Get data from one table with foreign_table and update to another in TCA

I'm modifying an image upload extension and I'm working on a feature where images can be placed in categories.
Right now the categories are listed in a select field that uses foreign_table to get the categories from a table (called tx_gallery_categories) and when saved the category Id (the value in the option field) is saved to table called tx_gallery_items.
But that column is no longer needed (i was wrong the first time). Depending on what category you choose I want TCA to update a table called tx_gallery_itemsCategory and set the categoryId where itemId is equal to the saved images uid
Here is the TCA (i have removed all other columns beside categoryId) and categoryId is the one I want to move out from this, I think, and in to it's own TCA which is connected to tx_gallery_itemsCategory:
$TCA["tx_gallery_items"] = array (
"ctrl" => $TCA["tx_gallery_items"]["ctrl"],
"interface" => array (
"showRecordFieldList" => "hidden,oid,filename, videoembedcode,caption"
),
"feInterface" => $TCA["tx_gallery_items"]["feInterface"],
"columns" => array (
"categoryId" => Array (
"exclude" => 1,
"label" => "LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items.categories",
"config" => Array (
"type" => "select",
"foreign_table" => "tx_gallery_categories",
// "foreign_table_where" => " true"
// "itemsProcFunc" => "tx_gallery_getImageCategories->getCategories"
// 'default' => '123'
)
),
),
"types" => array (
"0" => array("showitem" => "hidden, oid, filename, categoryId, videoembedcode, caption, linkpid")
)
);
$TCA["tx_gallery_categories"] = array (
"ctrl" => $TCA["tx_gallery_categories"]["ctrl"],
"interface" => array (
"showRecordFieldList" => "categoryTitle"
),
"feInterface" => $TCA["tx_gallery_categories"]["feInterface"],
"columns" => array (
"categoryTitle" => Array (
"exclude" => 0,
"label" => "LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items.categories",
"config" => Array (
"type" => "text",
"cols" => "30",
"rows" => "5",
)
)
),
"types" => array (
"0" => array("showitem" => "categoryTitle")
)
);
But instead of it working like that I want to save the images uid from tx_gallery_items to another table called tx_gallery_itemsCategory which is a many to many table between tx_gallery_items and tx_gallery_categories
Here are the tables:
tx_gallery_items:
uid | pid | ... (and many more but only uid is relevant)
432 | 34 | ...
tx_gallery_itemsCategory:
id | itemId | categoryId
1 | 432 | 1
tx_gallery_categories:
uid | pid | categoryTitle
1 | 34 | example category
And here is the ext_tables.php
$TCA["tx_gallery_items"] = array (
"ctrl" => array (
'title' => 'LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items',
'label' => 'filename',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'sortby' => 'sorting',
'delete' => 'deleted',
'enablecolumns' => array (
'disabled' => 'hidden',
),
'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php',
'iconfile' => t3lib_extMgm::extRelPath($_EXTKEY).'icon_tx_gallery_items.gif',
),
"feInterface" => array (
"fe_admin_fieldList" => "hidden, oid, filename, category, videoembedcode, caption, linkpid, categoryId",
)
);
$TCA["tx_gallery_categories"] = array (
"ctrl" => array (
'title' => 'LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items',
'label' => 'categoryTitle',
'tstamp' => 'tstamp',
'sortby' => 'sorting',
'delete' => 'deleted',
// 'enablecolumns' => array (
// 'disabled' => 'hidden',
// ),
'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php',
'iconfile' => t3lib_extMgm::extRelPath($_EXTKEY).'icon_tx_gallery_items.gif',
),
// "feInterface" => array (
// "fe_admin_fieldList" => "uid, pid, categoryTitle, categoryDescription, tstamp, sorting, deleted, hidden, categorySlug",
// )
);
So my question is (i think) how can I get the uid from the current image the user is editing and save it to another table.
This is my first try with TCA and I'm very confused on how all this is connected.
I hope that anyone knows this better than me :)
Thanks.
There is the hook concept implemented in the tcemain component. There is one called processDatamap_postProcessFieldArray which is invoked when any record is saved in the backend. Thus, you can check whether it's "yours" and do your other queries or whatever you want to change.
There is an example of how to use this feature. Although it is pretty old, it should still be working that way.