Unable to create image in magento api if product SKU contains slash(/) - magento

I'm trying to create an image via magento image api by following the same code in this magento doc.
And its working fine except the SKU contains slash(/) character.
SKU: SPA-1XCHOC12/DS0
Here is the Error shows in httpd/error_log:
[Fri Feb 21 07:35:33 2014] [error] [client 8.35.201.40] PHP Fatal error: Uncaught SoapFault exception: [104] Cannot create image. in /var/www/html/product_api/image.php:22\nStack trace:\n#0 /var/www/html/product_api/image.php(22): SoapClient->__call('call', Array)\n#1 /var/www/html/product_api/image.php(22): SoapClient->call('67da4ad39466d6e...', 'product_media.c...', Array)\n#2 {main}\n thrown in /var/www/html/product_api/image.php on line 22
To identify the exact issue, i have added this code
$this->_fault('not_created', $e->getMessage()); in app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api.php
And this is the error:
[Fri Feb 21 07:41:56 2014] [error] [client 8.35.201.42] PHP Fatal error: Uncaught SoapFault exception: [104] Folder 'SPA-1XCHOC12' isn't writeable in /var/www/html/product_api/image.php:22\nStack trace:\n#0 /var/www/html/product_api/image.php(22): SoapClient->__call('call', Array)\n#1 /var/www/html/product_api/image.php(22): SoapClient->call('7f82eac2c509869...', 'product_media.c...', Array)\n#2 {main}\n thrown in /var/www/html/product_api/image.php on line 22
And media/catalog/product folder permission is 777. Still showing the same error.
Here is my Code:
Post Values are sku = 'SPA-1XCHOC12/DS0' and image_url='http://example.com/11233.jpg'
$sessionId = $proxy->login($api_user, $api_pwd);
$newImage = array(
'file' => array(
'name' => $_POST['sku'],
'content' => base64_encode(file_get_contents($_POST['img_url'])),
'mime' => 'image/jpeg'
),
'position' => 0,
'types' => array('small_image', 'image', 'thumbnail'),
'exclude' => 0
);
$imageFilename = $proxy->call($sessionId, 'product_media.create', array($_POST['sku'], $newImage));

Since your image is being generated by the sku, which you are sending to the routine manually, then why not clean it up there. It won't affect anything else.
Post Values are sku = 'SPA-1XCHOC12/DS0' and image_url='http://example.com/11233.jpg'
$sessionId = $proxy->login($api_user, $api_pwd);
// Replace slashes like waldek_c suggested
$sku_filename = str_replace("/","_",$_POST['sku']).".jpg";
$newImage = array(
'file' => array(
'name' => $sku_filename, // Put filtered $sku_filename var here from above
'content' => base64_encode(file_get_contents($_POST['img_url'])),
'mime' => 'image/jpeg'
),
'position' => 0,
'types' => array('small_image', 'image', 'thumbnail'),
'exclude' => 0
);
$imageFilename = $proxy->call($sessionId, 'product_media.create', array($_POST['sku'], $newImage));
The image filename will be SPA-1XCHOC12_DS0.jpg instead of SPA-1XCHOC12/DS0.

Related

SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.webservicex.net/globalweather.asmx?WSDL' :

I am getting the same error with each and every wsdl url, that I have got as example while researching but am still getting the same error.
I have tried working with ssl and each and every suggestions seems to be a dead end as they do not resolve my issues.I have also set extension to openssl.
Here's the code I am using with Laravel.
ini_set("soap.wsdl_cache_enabled", "0");
ini_set("default_socket_timeout", "300");
ini_set ( 'max_execution_time' , 180);
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
);
$params = array ('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => false, 'soap_version' => SOAP_1_2, 'trace' => 1, 'exceptions' => 1,'user_agent' => 'PHPSoapClient', "connection_timeout" => 180, 'stream_context' => stream_context_create($opts) );
$url = "http://www.webservicex.net/globalweather.asmx?WSDL";
try{
$client = new SoapClient($url,$params);
dd($client->GetCitiesByCountry(['CountryName' => 'Peru'])->GetCitiesByCountryResult);
}
catch(SoapFault $fault) {
echo '<br>'.$fault;
}
This is the error that I am getting
SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.webservicex.net/globalweather.asmx?WSDL' :
I have tried more than 3 wsdl end points to check why the code is not working,but it seems that the my server is unable to connect to any of the host servers.
Thanks in advance.

Using and Configuring Zend Session and Zend Cache Memcached - Zend Framework 2.3

Actually, I'm using "standard" sessions manager config:
http://framework.zend.com/manual/current/en/modules/zend.session.manager.html
I want to use cache and save my session's data into server's cache (memcached) for improves performances and scalability.
I set php.ini like this (localhost memcached):
session.save_handler=memcached
session.save_path= "tcp://127.0.0.1"
and it show this error:
Warning: session_start(): Cannot find save handler 'memcached' - session startup failed in C:\Program Files (x86)\xampp\htdocs\Zend-application\vendor\zendframework\zendframework\library\Zend\Session\SessionManager.php on line 98
So, I don't understand how to configure my config/autoload/global.php and module/application/module.php. it's my first time that I want to implement memcached and caching in general. thanks, so much!
I tried to modify module/application/module.php like this:
---add session and cache ---
use Zend\Session\Config\SessionConfig;
use Zend\Session\Container;
use Zend\Cache\StorageFactory;
use Zend\Session\SaveHandler\Cache;
use Zend\Session\SessionManager;
use Zend\Session\Validator\HttpUserAgent;
use Zend\Session\Validator\RemoteAddr;
--- end session and cache ---
public function onBootstrap($e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$this->initSession(array(
'remember_me_seconds' => 180,
'use_cookies' => true,
'cookie_httponly' => true,
'validators' => array(
'Zend\Session\Validator\RemoteAddr',
'Zend\Session\Validator\HttpUserAgent',
'phpSaveHandler' => 'memcached',
'savePath' => 'tcp://127.0.0.1',
)
));
}
public function initSession($config)
{
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->getValidatorChain()
->attach(
'session.validate',
array(new HttpUserAgent(), 'isValid')
)
->attach(
'session.validate',
array(new RemoteAddr(), 'isValid')
);
$cache = StorageFactory::factory(array(
'adapter' => array(
'name' => 'memcached',
'options' => array(
'server' => '127.0.0.1',
),
)
));
$saveHandler = new Cache($cache);
$sessionManager->setSaveHandler($saveHandler);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
but it shows this error:
Warning: ini_set() expects parameter 2 to be string, array given in C:\Program Files (x86)\xampp\htdocs\Zend-application\vendor\zendframework\zendframework\library\Zend\Session\Config\SessionConfig.php on line 88
Fatal error: Call to undefined method Zend\Stdlib\CallbackHandler::attach() in C:\Program Files (x86)\xampp\htdocs\Zend-application\module\Application\Module.php on line 68
this is my config/autoload/global.php
return array(
'db' => array(
'driver' => 'Pdo_Mysql',
'charset' => 'utf-8',
'dsn' => 'mysql:dbname=mydb;host=localhost',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
'session' => array(
'config' => array(
'class' => 'Zend\Session\Config\SessionConfig',
'options' => array(
'name' => 'zend-application',
),
),
'storage' => 'Zend\Session\Storage\SessionArrayStorage',
'validators' => array(
'Zend\Session\Validator\RemoteAddr',
'Zend\Session\Validator\HttpUserAgent',
),
),
);
Hoping it'll help someone, I resolved my issue. I'm working in Win7 enviroment and memcached doesn't work on it! I changed :
session.save_handler=memcached
session.save_path= "tcp://127.0.0.1"
to
session.save_handler=memcache
session.save_path= "tcp://127.0.0.1:11211"
I restored the "standard" session manager config and memcache works correctly. When I'll transfer the entire site to apache server, I'll change php.ini for using memcached.
http://framework.zend.com/manual/current/en/modules/zend.session.manager.html

While create adset then I got error 'Invalid parameter'

I am using FB Ads API, and successfully created campaigns and get the ID from Facebook. In the next step to create adset with below code then got error.
// Call create using an array of parameters.
$data = array(
AdSetFields::NAME => 'My AdSet',
AdSetFields::BID_TYPE => 'CPC',
AdSetFields::BID_INFO => array(
'CLICKS' => 500,
),
AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_ACTIVE,
AdSetFields::DAILY_BUDGET => 200,
AdSetFields::CAMPAIGN_GROUP_ID => $campaign_id,
AdSetFields::TARGETING => array(
'geo_locations' => array(
'countries' => array(
'US',
'GB',
),
),
),
);
$ad_set = new AdSet(null, $account->id);
$ad_set->create($data);
Fatal error: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message 'Invalid parameter' in /www/facebookads/src/FacebookAds/Http/Exception/RequestException.php:129
I got solution for this error,
DAILY_BUDGET - increased upto 4000 then it is converted to INR 40.00
then I created adset successfully

Error during assigning product image through soap api Magento

HI i have just start learning soap api in magento . In this i have create a product through soap and now i want to assign product images through it.
for that i am using below code
<?php $client = new SoapClient('http://localhost/magento1.9/index.php/api/v2_soap/?wsdl');
$session = $client->login('111111', '111111');
$newImage = array(
'file' => array(
'name' => 'file_name',
'content' => base64_encode(file_get_contents('heart_circle.png')),
'mime' => 'image/jpeg'
),
'label' => 'Cool Image Through Soap',
'position' => 2,
'types' => array('small_image'),
'exclude' => 0
);
$imageFilename = $client->call($session, 'product_media.create', array('product_sku', $newImage));
var_dump($imageFilename);
?>
but i am getting below error Fatal error: Uncaught SoapFault
exception: [Client] Function ("call") is not a valid method for this
service in /var/www/soap.php:19 Stack trace: #0 /var/www/soap.php(19):
SoapClient->__call('call', Array) #1 /var/www/soap.php(19):
SoapClient->call('92b56ed9ed1c9b5...', 'product_media.c...', Array) #2
{main} thrown in /var/www/soap.php on line 19
Please suggest me where i am doing mistake. thanks
Hi i have found the issue it was the wrong soap version mention in the url
http://localhost/magento1.9/index.php/api/v2_soap/?wsdl //previous
http://localhost/magento1.9/index.php/api/soap/?wsdl // new
thanks

ReferenceError: MediabrowserUtility is not defined in magento wysiwyg

my question that i am using wysiwyg editor in magento admin side i checked every page every thing is right no error in code when click on the insert image they generate the error and can not works fine so help me anyone they face this type of error. error is
"ReferenceError: MediabrowserUtility is not defined"
thanks
$wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig(array('tab_id' => 'form_section'));
$wysiwygConfig["files_browser_window_url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg_images/index');
$wysiwygConfig["directives_url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg/directive');
$wysiwygConfig["directives_url_quoted"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg/directive');
$wysiwygConfig["widget_window_url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/widget/index');
$wysiwygConfig["files_browser_window_width"] = (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_width');
$wysiwygConfig["files_browser_window_height"] = (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_height');
$plugins = $wysiwygConfig->getData("plugins");
$plugins[0]["options"]["url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/system_variable/wysiwygPlugin');
$plugins[0]["options"]["onclick"]["subject"] = "MagentovariablePlugin.loadChooser('".Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/system_variable/wysiwygPlugin')."', '{{html_id}}');";
$plugins = $wysiwygConfig->setData("plugins",$plugins);
$fieldset->addField('question_details', 'editor', array(
'name' => 'content',
'label' => Mage::helper('supportportal')->__('Details'),
'title' => Mage::helper('supportportal')->__('Details'),
'style' => 'width:600px; height:300px;',
'config' => $wysiwygConfig,
'wysiwyg' => true,
'required' => true,
));
The error is due to a missing configuration setting which is assigned to the WYSWIG addField() array.
If you open your Form.php simply add the following above the WYSIWYG field,
$configSettings = array( 'add_widgets' => false, 'add_variables' => false, 'add_images' => false, 'files_browser_window_url'=> $this->getBaseUrl().'admin/cms_wysiwyg_images/index/'));
Then modify your WYSIWYG form field (see highlighted below),
$fieldset->addField('post_content', 'editor', array(
'name' => 'post_content',
'label' => Mage::helper('faqs')->__('Answer'),
'title' => Mage::helper('faqs')->__('Answer'),
'style' => 'width:700px; height:500px;',
'wysiwyg' => true,
'config' => $configSettings
));
for detail you can see this link and also read some comments on that
hope this will sure help you

Resources