I am trying to utilize this plugin to import an xml file, I have a simple xml file.
<MYData>
<login_details>
<unique_ref>1-61</unique_ref>
<login_name>tomme</login_name>
<login>me</login>
<password>me</password>
<file1>Test</file1>
<file2/>
<file3/>
<file4/>
</login_details>
<login_details>
<unique_ref>1-61</unique_ref>
<login_name>tony</login_name>
<login>tony</login>
<password>tony</password>
<file1>Test1</file1>
<file2/>
<file3/>
<file4/>
</login_details>
</MYData>
but can only manage to import 3 nodes I wrongly thought I could simply append this code $postBlog = $blogPost::create(['unique_ref' => $item->unique_ref, 'slug' => Str::slug($item->unique_ref), 'login_name' => $item->login_name, 'login' =>$item->login);but the last node does not update the database any help would be gratefully appreciated as I am new to coding in October frame work.
I found this piece of code that works but my model requires the slug to have a value
foreach ($xmls->login_details as $row => $data) {
try {
if (!$refno_prop = array_get($data, 'refno_prop')) {
}
/*
* Find or create
*/
$post = Post::make();
if ($this->update_existing) {
$post = $this->findDuplicatePost($data) ?: $post;
}
$postExists = $post->exists;
/*
* Set attributes
*/
$except = ['id', 'categories', 'author_email'];
foreach (array_except($data, $except) as $attribute => $value) {
$post->{$attribute} = $value ?: null;
}
$post->forceSave();
/*
* Log results
*/
if ($postExists) {
$this->logUpdated();
}
}
catch (Exception $ex) {
$this->logError($row, $ex->getMessage());
}
}
so I am looking for a method to add the slug value from an existing node I also haven't figured out how to stop the same data from being added to the database
Related
I'm able retrieve the list items on Sharepoint via the code below:
public function getListItems($listName){
$params = ['listName' => $listName];
try {
$rawXMLresponse = $this->soapClient->GetListItems($params)->GetListItemsResult->any;
return $rawXMLresponse;
} catch (SoapFault $fault) {
$this->writeError($fault);
}
}
In Sharepoint the retrieved list items that I have are links that contain Documents (Folder, Files, etc.) What I need to do is to somehow display that contents for each link.
These are the available operations that I can use:
I already tried using the GetAttachmentCollection which receives a listName and a listItemID which just returns an empty array for any given ListItemID that I put:
public function getAttachmentCollection($listName){
$params = [
'listName' => $listName,
'listItemID' => '15'
];
try {
$rawXMLresponse = $this->soapClient->GetAttachmentCollection($params)->GetAttachmentCollectionResult->any;
$dom = new \DOMDocument();
$dom->loadXML($rawXMLresponse);
$result = array();
foreach($dom->getElementsByTagName('Attachments') as $attachments) {
foreach($attachments->getElementsByTagName('Attachment') as $attachment) {
$result[] = $attachment->nodeValue;
}
}
var_dump($result);
} catch (SoapFault $fault) {
$this->writeError($fault);
}
}
I have also tried asking this question to the Sharepoint Stack but they recommend switching REST API which is not an option for me.
Here's the list items response XML:
<listitems xmlns:s="uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" xmlns:dt="uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<rs:data ItemCount="15">
<z:row ows_LinkTitle="DOCUMENTS" ows_Is_x0020_Web="1" ows_Hidden="0" ows_Offline_x0020_Support="1"
ows_Offline="1" ows_Offline_x0020_Only_x0020_Wifi="1" ows_Offline_x0020_Download_x0020_Doc="1"
ows_Offline_x0020_Max_x0020_Document="10.0000000000000" ows_Swipe_x0020_Documents="1"
ows_Offline_x0020_Background="1" ows_Layout_x0020_Mode="Normal" ows_TabsEnable="0"
ows_ManualOrderSupport="1" ows_Preview_x0020_On_x0020_Tap="1" ows_ShowInSaveToOtherLocation="1"
ows__Level="1" ows_UniqueId="15;#{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" ows_FSObjType="15;#0"
ows_Created_x0020_Date="15;#2018-06-13 11:06:50" ows_Modified="2018-06-13 11:09:01" ows_MetaInfo="15;#"
ows_Title="DOCUMENTS" ows_ID="15" ows_owshiddenversion="2" ows_Created="2018-06-13 11:06:50"
ows_FileLeafRef="15;#15_.000" ows_PermMask="0xxxxxxxxxxxxxxx" ows_FileRef="15;#Lists/ListName/15_.000"
ows__ModerationStatus="0"/>
14 more ...
</rs:data>
</listitems>
Any help is appreciated. Thanks!
I have a field reply_level in a reply table.
protected function buildDomainObject(array $row)
{
$reply = new Reply();
$reply->setId($row['reply_id']);
$reply->setAuthor($row['reply_author']);
$reply->setContent($row['reply_content']);
$reply->setComParent($row['com_id']);
$reply->setLevel($row['reply_level']);
if (array_key_exists('art_id', $row))
{
$commentaireId = $row['art_id'];
$article = $this->articleDAO->find($commentaireId);
$reply->setArticle($article);
}
return $reply;
}
public function save(Reply $reply) {
$commentData = array(
'reply_content' => $reply->getContent(),
'reply_author' => $reply->getAuthor(),
'com_id' => $reply->getComParent(),
'art_id' => $reply->getArticle()->getId(),
'reply_level' => $reply->getLevel()
);
if ($reply->getId()) {
// update comment
$this->getDb()->update('t_reply', $commentData, array('reply_id' => $reply->getId()));
} else {
// The comment has never been saved : insert it
$this->getDb()->insert('t_reply', $commentData);
// Get the id of the newly created comment and set it on the entity.
$id = $this->getDb()->lastInsertId();
$reply->setId($id);
}
}
I would like to pass several values to reply_level, either reply_level, reply_level1, reply _level2, reply_level3 ...(Depending on the level of the sub-comment). How to pass multiple values ? i use pdo mysql.
Thank you
I am new to magento and I am not able to make out how one can remove the unwanted states from dropdown list in magento. I tried to edit my below function as per this link http://doejo.com/blog/magento-how-to-remove-certain-states-from-state-region-list-at-checkout-or-registration/ but it did not work. Below i sthe code for removing unwanted states but when I add to my class in local folder, not getting any results.
$excludeRegions = array('AE','AA');
foreach ($collection as $region) {
if (!$region->getRegionId()) {
continue;
}
***//Here is the code from the link given
//BOF Custom Logic Here***
$regionCode = $region->getCode();
$this->_select->from(array('region'=>$this->_regionTable),
array('region_id'=>'region_id', 'country_id'=>'country_id', 'code'=>'code', 'default_name'=>'default_name')
)->where('code NOT IN (?)', $exclude_regions);
_getRegions function edited as per above code and link respectively.
protected function _getRegions($storeId)
{
$countryIds = array();
$countryCollection = $this->getCountryCollection()->loadByStore($storeId);
foreach ($countryCollection as $country) {
$countryIds[] = $country->getCountryId();
}
/** #var $regionModel Mage_Directory_Model_Region */
$regionModel = $this->_factory->getModel('directory/region');
/** #var $collection Mage_Directory_Model_Resource_Region_Collection */
$collection = $regionModel->getResourceCollection()
->addCountryFilter($countryIds)
->load();
$regions = array(
'config' => array(
'show_all_regions' => $this->getShowNonRequiredState(),
'regions_required' => $this->getCountriesWithStatesRequired()
)
);
$excludeRegions = array('AE','AA');
foreach ($collection as $region) {
if (!$region->getRegionId()) {
continue;
}
***//Here is the code from the link given
//BOF Custom Logic Here***
$regionCode = $region->getCode();
$this->_select->from(array('region'=>$this->_regionTable),
array('region_id'=>'region_id', 'country_id'=>'country_id', 'code'=>'code', 'default_name'=>'default_name')
)->where('code NOT IN (?)', $exclude_regions);
//EOF Custom Logic Here
$regions[$region->getCountryId()][$region->getRegionId()] = array(
'code' => $region->getCode(),
'name' => $this->__($region->getName())
);
}
return $regions;
}
After making the above changes, I tried below steps as my code is in /app/code/core/Mage/Directory/Helper/Data.php
Create a module Vids_Directory in pool local like app/code/local/Vids/Directory
Create app/etc/modules/Vids_Directory.xml
Create app/code/local/Vids/Directory/etc/config.xml
create app/code/local/Vids/Helper/Data.php
I'm creating a new widget that allows custom text/HTML to be added to the page. I noticed that if you enter text containing double-quotes, the first occurrence of it and everything after gets cut off, so that you're missing data when you try to edit the widget again.
To make sure I didn't screw something up, I was able to verify this issue on a fresh install of Magento (1.7), by adding a stock widget -- Catalog Product Link -- to the page. If you set the Anchor Custom Text to something with double-quotes, insert, and edit again, you will see the text has been truncated.
I'm not sure where the problem occurs. The data is successfully written to the tinyMCE content element, but somehow gets malformed between there and an Ajax.Request call for the admin/widget/loadOptions route.
I found a related article here:
http://www.behrendt.io/2013/04/12/using-a-wysiwyg-editor-in-a-magento-widget/
The author mentions at the bottom a need for overriding a controller to use base64 encoding when transmitting data for widgets. This seems like it might work for me, but I wanted to be sure.
Here's a visual example of the problem I'm experiencing:
Anyone seen this before? Know where it comes from? How to fix? :) Thanks.
Looks like that article put me in the right direction, by overriding Mage_Widget_Adminhtml_WidgetController:
http://www.behrendt.io/2013/04/12/using-a-wysiwyg-editor-in-a-magento-widget/
I took his solution a step further and decided to encode ALL values when building the widget code:
# Namespace_Module_Adminhtml_WidgetController extends Mage_Widget_Adminhtml_WidgetController
public function buildWidgetAction()
{
$type = $this->getRequest()->getPost('widget_type');
$params = $this->getRequest()->getPost('parameters', array());
$asIs = $this->getRequest()->getPost('as_is');
if($type == 'namespace/module_widget')
{
foreach($params as $key => $value)
{
$params[$key] = base64_encode($value);
}
}
$html = Mage::getSingleton('widget/widget')->getWidgetDeclaration($type, $params, $asIs);
$this->getResponse()
->setBody($html);
}
This meant I also had to decode them when loading the widget for editing:
# Namespace_Module_Adminhtml_WidgetController extends Mage_Widget_Adminhtml_WidgetController
public function loadOptionsAction()
{
try {
$this->loadLayout('empty');
if( ($paramsJson = $this->getRequest()->getParam('widget')) )
{
$request = Mage::helper('core')->jsonDecode($paramsJson);
if(is_array($request))
{
$optionsBlock = $this->getLayout()->getBlock('wysiwyg_widget.options');
if(isset($request['widget_type']))
{
$optionsBlock->setWidgetType($request['widget_type']);
}
if(isset($request['values']))
{
if($optionsBlock->getWidgetType() == 'namespace/module_widget')
{
foreach($request['values'] as $key => $value)
{
$request['values'][$key] = base64_decode($value);
}
}
$optionsBlock->setWidgetValues($request['values']);
}
}
$this->renderLayout();
}
}
catch (Mage_Core_Exception $e)
{
$result = array('error' => true, 'message' => $e->getMessage());
$this->getResponse()
->setBody(Mage::helper('core')->jsonEncode($result));
}
}
And finally, in my widget block, I had to decode all data on-the-fly:
# Namespace_Module_Block_Widget
public function getData($key = '', $index = null)
{
if('' === $key)
{
$data = $this->_data;
foreach($data as $key => $value)
{
if(is_scalar($value))
{
$data[$key] = base64_decode($value);
}
}
}
else
{
$data = parent::getData($key, $value);
if(is_scalar($data))
{
$data = base64_decode($data);
}
}
return $data;
}
It would be nice if a similar encoding mechanism was part of core code.
I have lot of products with custom options, now I have requirement to update only custom options through csv file. so how we can do this programatically?
i found one solution for updating custom options programatically here is the solution
$product = Mage::getModel('catalog/product')->load($product_id);
$values = array();
foreach ($product->getOptions() as $o) {
$p = $o->getValues();
}
}
foreach($p as $v)
{
$values[$v->getId()]['option_type_id']= $v->getId();
$values[$v->getId()]['title']= 'test';
$values[$v->getId()]['price']= 23;
$values[$v->getId()]['price_type']= 'fixed';
$values[$v->getId()]['sku']= $value1;
}
$v->setValues($values);
$v->saveValues();
$product->save();
hope this help someone
this only update custom options value
I think this is also useful...
If you are customize the products .
<?php
$magePath = 'app/Mage.php';
require_once $magePath;
Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product_ids = array(1,2,167);
$productmodel = Mage::getModel('catalog/product');
foreach ($product_ids as $product_id) {
/**i use this two arrays for collecte value because i uses inside setData of
current option*/
$cos=array();
$co=array();
$product = $productmodel->load($product_id);
$options = $product->getProductOptionsCollection();
if (isset($options)) {
foreach ($options as $o) {
$title = $o->getTitle();
/**
this block is for changing information of specific option from collection options inside
current product
the save method for this option in end of code
*/
if ($title == "Line 1/Front") {
$o->setProduct($product);
$o->setTitle("Line 1/Ftont");
$o->setType("drop_down");
$o->setIsRequire(1);
$o->setSortOrder(0);
}
/**
this block for update or add information of specific value inside current option
*/
$optionType = $o->getType();
//test type
if ($optionType == "drop_down") {
//getting collection of value related to current option
$values = $o->getValuesCollection();
$found = false;
foreach ($values as $k => $v) {
//test existing of value for update
if (1 == preg_match("/said$/i", $v->getTitle())) {
//update and save
$v->setTitle("morad")
->setSku("kk")
->setPriceType("fixed")
->setSortOrder(0)
->setPrice(floatval(13.0000));
$v->setOption($o)->save();
/**
this ligne is important i collecte all value required for normalize save function
related to current option
*/
$cos[]=$v->toArray($co);
}
}
/**
create new value object you can use $option->getValueInstance() for working with
getSingleton
*/
$value = Mage::getModel('catalog/product_option_value');
$value->setOption($o)
->setTitle('valueiwant')
->setSku("nn")
->setPriceType("fixed")
->setSortOrder(1)
->setPrice(12)
/**
this ligne is important (relation forigien key) for related this new value
to specific option
*/
->setOptionId($o->getId());
$value->save();
/**
this ligne is important i collecte all value required for normalize save function
related to current option
*/
$cos[]=$value->toArray($co);
}
$o->setData("values",$cos)->save();
//var_dump($cos);
}
}
}
Do you create a module to do that ? If you do, you must use the cron system of Magento and call a method of a custom model :
<config>
<!--...-->
<crontab>
<jobs>
<company_test>
<schedule>
<cron_expr>0,15,30,45 * * * *</cron_expr>
</schedule>
<run>
<model>test/testmodel::testMethod</model>
</run>
</company_module>
</jobs>
</crontab>
</config>
When this is done, you can update the option of a specific product by using the model Mage_Catalog_Model_Product_Option. I don't know how the CSV is made, but the algorithm can be something like that :
// foreach option
/** #var $opt Mage_Catalog_Model_Product_Option */
$opt = Mage::getModel('catalog/product_option');
$opt->setProduct($product);
$optionArray = array(
'is_delete' => 0,
'title' => 'Blabla',
'previous_group' => '',
'previous_type' => '',
'type' => 'field', //can be radio, drop_down, file, area...
'is_require' => 0,
'sort_order' => 42,
'values' => array()
);
$opt->addOption($optionArray);
$opt->saveOptions();
// end foreach
Also check this link : http://subesh.com.np/2009/12/adding-custom-options-product-magento/