How do you get the database column properties of the attributes of a model? Like datatype, default value, size, etc.
You can use $customer_model->getTableSchema() or Customer::getTableSchema()
Provides you with something like this:
yii\db\TableSchema#1 (
[schemaName] => null
[name] => 'customers'
[fullName] => 'customers'
[primaryKey] => [
0 => 'customerID'
]
[sequenceName] => ''
[foreignKeys] => [
0 => [
0 => 'orders'
'ord_customerID' => 'customerID'
]
]
[columns] => [
'customerID' => yii\db\ColumnSchema#2 (
[name] => 'customerID'
[allowNull] => false
[type] => 'integer'
[phpType] => 'integer'
[dbType] => 'int(10) unsigned'
[defaultValue] => null
[enumValues] => null
[size] => 10
[precision] => 10
[scale] => null
[isPrimaryKey] => true
[autoIncrement] => true
[unsigned] => true
[comment] => ''
)
...
Related
i am making an image storage function with laravel job queue via googledrive. i am trying to initialize and store my photo. It works with the code:
$filePut = file_get_contents($this->path);
Storage::cloud()->put($this->name, $filePut);
but i can't get the return id
i am changing to another method and here is my 2nd code:
public function handle(GoogleClient $googleDrive)
{
dd($googleDrive);
$driveService = new \Google_Service_Drive($googleDrive);
$fileMetadata = new \Google_Service_Drive_DriveFile([
'name' => $this->name,
]);
$file = $driveService->files->create($fileMetadata, [
'data' => file_get_contents($this->path),
'uploadType' => 'multipart',
'fields' => 'id',
]);
$driveService->getClient()->setUseBatch(true);
try {
$batch = $driveService->createBatch();
$userPermission = new \Google_Service_Drive_Permission([
'type' => 'anyone',
'role' => 'reader',
]);
$request = $driveService->permissions->create($file->id, $userPermission, ['fields' => 'id']);
$batch->add($request, 'user');
$results = $batch->execute();
} catch (\Exception $e) {
} finally {
$driveService->getClient()->setUseBatch(false);
}
I noticed the data received from dd($googleDrive) is no data :
App\Components\GoogleClient {#3225
#client: Google\Client {#3203
-auth: null
-http: null
-cache: null
-token: null
-config: array:29 [
"application_name" => ""
"base_path" => "https://www.googleapis.com"
"client_id" => ""
"client_secret" => ""
"credentials" => null
"scopes" => null
"quota_project" => null
"redirect_uri" => null
"state" => null
"developer_key" => ""
"use_application_default_credentials" => false
"signing_key" => null
"signing_algorithm" => null
"subject" => null
"hd" => ""
"prompt" => ""
"openid.realm" => ""
"include_granted_scopes" => null
"login_hint" => ""
"request_visible_actions" => ""
I try to store it before the queue then the $drivegoogle data I get is as follows:
Google\Client {#3146
-auth: null
-http: null
-cache: null
-token: array:6 [
"access_token" => "*************************************************************************************"
"expires_in" => "*************************************************************************************"
"scope" => "*************************************************************************************"
"token_type" => "*************************************************************************************"
"created" => "*************************************************************************************"
"refresh_token" => "*************************************************************************************"
]
-config: array:29 [
"application_name" => ""
"base_path" => "https://www.googleapis.com"
"client_id" => "*************************************************************************************"
"client_secret" => "*************************************************************************************"
"credentials" => null
"scopes" => null
"quota_project" => null
"redirect_uri" => null
"state" => null
"developer_key" => ""
"use_application_default_credentials" => false
"signing_key" => null
"signing_algorithm" => null
"subject" => null
"hd" => ""
"prompt" => ""
"openid.realm" => ""
"include_granted_scopes" => null
"login_hint" => ""
"request_visible_actions" =>
is there any workaround to get the id from the storage::put method, or is there another way to fix my current error, the error appears at new \Google_Service_Drive($googleDrive); constructor must be array or instance of Google\Client {"exception":"[object] (TypeError(code: 0): constructor must be array or instance of Google\\Client
$googleDrive = $googleDrive->getClient()
Thank you very much for reading this, its quite long!
I run my function:
public function createSpreadSheet()
{
$client = $this->getClient();
$service = new \Google_Service_Sheets($client);
// TODO: Assign values to desired properties of `requestBody`:
$requestBody = new \Google_Service_Sheets_Spreadsheet();
$response = $service->spreadsheets->create($requestBody);
echo '<pre>', var_export($response, true), '</pre>', "\n";
}
I got a result:
Google_Service_Sheets_Spreadsheet::__set_state(array(
'collection_key' => 'sheets',
'developerMetadataType' => 'Google_Service_Sheets_DeveloperMetadata',
'developerMetadataDataType' => 'array',
'namedRangesType' => 'Google_Service_Sheets_NamedRange',
'namedRangesDataType' => 'array',
'propertiesType' => 'Google_Service_Sheets_SpreadsheetProperties',
'propertiesDataType' => '',
'sheetsType' => 'Google_Service_Sheets_Sheet',
'sheetsDataType' => 'array',
'spreadsheetId' => '1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU',
'spreadsheetUrl' => 'https://docs.google.com/spreadsheets/d/1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU/edit',
'internal_gapi_mappings' =>
array (
),
modelData' =>
array (
),
'processed' =>
array (
),
'properties' =>
Google_Service_Sheets_SpreadsheetProperties::__set_state(array(
'autoRecalc' => 'ON_CHANGE',
'defaultFormatType' => 'Google_Service_Sheets_CellFormat',
'defaultFormatDataType' => '',
'iterativeCalculationSettingsType' => 'Google_Service_Sheets_IterativeCalculationSettings',
'iterativeCalculationSettingsDataType' => '',
'locale' => 'en_US',
'timeZone' => 'Etc/GMT',
'title' => 'Untitled spreadsheet',
'internal_gapi_mappings' =>
array (
),
'modelData' =>
array (
),
'processed' =>
array (
),
'defaultFormat' =>
Google_Service_Sheets_CellFormat::__set_state(array(
'backgroundColorType' => 'Google_Service_Sheets_Color',
'backgroundColorDataType' => '',
'bordersType' => 'Google_Service_Sheets_Borders',
'bordersDataType' => '',
'horizontalAlignment' => NULL,
'hyperlinkDisplayType' => NULL,
'numberFormatType' => 'Google_Service_Sheets_NumberFormat',
'numberFormatDataType' => '',
.........
.........
))
I access to the link it returned:
'https://docs.google.com/spreadsheets/d/1QlBQo_YHQpiiMBWn6b6wSMVWkiFRx4grJhPParXUUSU/edit'
it gives me this 'request access' page, then I press the request access
I open my email and get this:
Your message wasn't delivered to xxxxxx#xxxxxxxx.iam.gserviceaccount.com because the domain admanager-1x3x71x4x27x4.iam.gserviceaccount.com couldn't be found. Check for typos or unnecessary spaces and try again.
Is there something wrong and what should I do? I just want to open the file and check where it is.
Thank you very much!
I have upgraded from Cakephp3 v3 to v3.3 (using Composer) and I get the following error:
Deprecated (16384): Property $theme is deprecated.
Use $this->viewBuilder()->theme() instead in beforeRender().
[CORE/src/View/ViewVarsTrait.php, line 103]
But I can't find in my files where $theme is used. I have searched all my files for the keyword $theme and beforeRender, no relevant results.
This error is shown in all my pages, so it must be some file that is included in each one.
I have already searched on google for this issue, no relevant results either.
Has anyone else had this problem?
Full error stack:
$viewClass = null
$builder = object(Cake\View\ViewBuilder) {
[protected] _templatePath => 'Users'
[protected] _template => 'login'
[protected] _plugin => null
[protected] _theme => 'Orange'
[protected] _layout => null
[protected] _autoLayout => null
[protected] _layoutPath => null
[protected] _name => null
[protected] _className => null
[protected] _options => []
[protected] _helpers => []
}
$validViewOptions = [
(int) 0 => 'passedArgs'
]
$viewOptions = [
'passedArgs' => []
]
$option = 'passedArgs'
$this = object(App\Controller\UsersController) {
theme => 'Orange'
name => 'Users'
helpers => []
request => object(Cake\Network\Request) {}
response => object(Cake\Network\Response) {}
paginate => []
autoRender => false
components => []
View => null
plugin => null
passedArgs => []
modelClass => 'Users'
viewClass => null
viewVars => []
Flash => object(Cake\Controller\Component\FlashComponent) {}
Auth => object(Cake\Controller\Component\AuthComponent) {}
[protected] _responseClass => 'Cake\Network\Response'
[protected] _components => object(Cake\Controller\ComponentRegistry) {}
[protected] _validViewOptions => [
(int) 0 => 'passedArgs'
]
[protected] _eventManager => object(Cake\Event\EventManager) {}
[protected] _eventClass => '\Cake\Event\Event'
[protected] _tableLocator => object(Cake\ORM\Locator\TableLocator) {}
[protected] _modelFactories => [
'Table' => [
[maximum depth reached]
]
]
[protected] _modelType => 'Table'
[protected] _viewBuilder => object(Cake\View\ViewBuilder) {}
}
$deprecatedOptions = [
'layout' => 'layout',
'view' => 'template',
'theme' => 'theme',
'autoLayout' => 'autoLayout',
'viewPath' => 'templatePath',
'layoutPath' => 'layoutPath'
]
$new = 'theme'
$old = 'theme'
Cake\Controller\Controller::createView() - CORE/src/View/ViewVarsTrait.php, line 103
Cake\Controller\Controller::render() - CORE/src/Controller/Controller.php, line 616
Cake\Http\ActionDispatcher::_invoke() - CORE/src/Http/ActionDispatcher.php, line 131
Cake\Http\ActionDispatcher::dispatch() - CORE/src/Http/ActionDispatcher.php, line 99
Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 65
[main] - ROOT/webroot/index.php, line 21
Turns out that in AppController a custom theme (Orange in my case) needs to be declared as:
public function beforeRender(Event $event)
{
$this->viewBuilder()->theme('Orange');
}
and not like
public $theme = 'Orange';
Many thanks to #arilia for helping me with this.
Cannot reverse output, tried with array_reverse and usort.
I'm trying to import products from an XML to Magento with magmi datapump, works fine but I need the output in reverse order for Magento to link simple products with configurable products,
Any ideas?
$xml = simplexml_load_file("23.xml") or die("Error: Cannot create object");
foreach($xml->wapiitems->record as $book) {
$item = $book->fields->itemno;
if (strlen($item) <= 6) {
$type = "configurable";
$ca = "color,size";}
else {
$type = "simple";
$ca = "";}
$newProductData = array(
'sku' => (string)$book->fields->itemno, // name
'type' => (string)$type, // sku
'color' => (string)$book->subtables->descriptions->record->fields->variant1name, // special price
'size' => (string)$book->subtables->descriptions->record->fields->variant3name, // price
'attribute_set' => 'Default', // attribute_set
'store' => 'admin',
'name' => (string)$book->subtables->descriptions->record->fields->description, // full description
'configurable_attributes' => (string)$ca // short description
);
//$dp->ingest($newProductData);
echo "</br>";
print_r ($newProductData);
$newProductData=null; //clear memory
unset($newProductData); //clear memory
}
unset($xml);
$dp->endImportSession(); // end import
My output is:
Array ( [sku] => 90349 [type] => configurable [color] => [size] => [attribute_set] => Default [store] => admin [name] => [configurable_attributes] => color,size )
Array ( [sku] => 903490101004 [type] => simple [color] => Red [size] => 4 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
Array ( [sku] => 903490101005 [type] => simple [color] => Black [size] => 5 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
Array ( [sku] => 903490101006 [type] => simple [color] => Black [size] => 6 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
But I need this:
Array ( [sku] => 903490101006 [type] => simple [color] => Black [size] => 6 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
Array ( [sku] => 903490101005 [type] => simple [color] => Black [size] => 5 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
Array ( [sku] => 903490101004 [type] => simple [color] => Red [size] => 4 [attribute_set] => Default [store] => admin [name] => Q-Irine Cover [configurable_attributes] => )
Array ( [sku] => 90349 [type] => configurable [color] => [size] => [attribute_set] => Default [store] => admin [name] => [configurable_attributes] => color,size )
Not sure how Magmi Datapump is linking the simple and configurable products based on your example, but assuming that all that is required for your problem is that configurable products get imported after the simple products, you could do something like this:
Create an intermediate array of product records after pulling them out of XML by changing $newProductData = array(...) to $newProductData[] = array(...)
Now use something like this to sort your intermediate array by product type:
usort($newProductData, function($a, $b)
{
if ($a['type'] == 'configurable' && $b['type'] == 'simple') {
return 1;
} else if ($a['type'] == 'simple' && $b['type'] == 'configurable') {
return -1;
} else {
return strnatcmp($a['sku'], $b['sku']);
}
});
Finally, iterate over the sorted array and complete the import:
foreach ($newProductData as $data) {
$dp->ingest($data);
}
Is it possible while creating new users with AvS_Fastsimpleimporter to add more than the standard address ?
Currently my array "data" looks like this
'email' => $kunde['email'],
'_website' => $_website,
'_store' => $_website . 'store',
'confirmation' => '',
'created_at' => $created_at,
'created_in' => 'Import',
'disable_auto_group_change' => 0,
'firstname' => $kunde['name_1'],
'group_id' => 3,
'kontonummer' => $kunde['kontonr'],
'kundennummer' => $kunde['kundennr'],
'lastname' => $lastname,
'password_hash' => $password_hash,
'store_id' => 0,
'website_id' => $country['id'],
'_address_city' => $kunde['ort'],
'_address_country_id' => $kunde['land'],
'_address_fax' => $kunde['fax'],
'_address_firstname' => $kunde['name_1'],
'_address_lastname' => $lastname,
'_address_postcode' => $kunde['plz'],
'_address_street' => $kunde['strasse'],
'_address_telephone' => $_address_telephone,
'_address_vat_id' => $kunde['ust_id'],
'_address_default_billing_' => 1,
'_address_default_shipping_' => 1,
And i want to add a second address with the AvS_Simpleimporter.
I tried to add a second array in data like this:
array_push($data, array(
'email' => null,
'_website' => null,
'_address_city' => checkRequiredInput($address['ort']),
'_address_country_id' => $address['land'],
'_address_firstname' => checkRequiredInputVadr($address['name_1']),
'_address_lastname' => checkRequiredInputVadr($address['name_2']),
'_address_postcode' => checkRequiredInput($address['plz']),
'_address_street' => checkRequiredInput($address['strasse']),
'_address_default_billing_' => 0,
'_address_default_shipping_' => 0,
));
And then executing with
$importer = Mage::getModel('fastsimpleimport/import');
$importer->setIgnoreDuplicates('password_hash')->processCustomerImport($data);
But this currently doesn't work. The second address is added as an extra array to data like this
.... data array
....
'_address_default_billing_' => 1
'_address_default_shipping_' => 1
[0] => 'email' => bla bla
'_website' => bla bla
and so son
Any help ?
Multiple addresses are imported as additional rows. Hence you need to:
'_address_country_id' => array($country1,$country2),
'_address_city' => array($city1, $city2),
....