Skip to content

Instantly share code, notes, and snippets.

@pitkane
Created January 25, 2017 05:59
Show Gist options
  • Save pitkane/2f2cf594e8df1e309be528b72ebd9e9d to your computer and use it in GitHub Desktop.
Save pitkane/2f2cf594e8df1e309be528b72ebd9e9d to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Getopt::Long;
use DE_EPAGES::Core::API::Script qw(RunScript);
use DE_EPAGES::Database::API::Connection qw(RunOnStore);
use DE_EPAGES::Object::API::Factory qw(LoadObject LoadObjectByPath ExistsObject ExistsObjectByGUID LoadRootObject LoadObjectByGUID ExistsObjectByPath LoadClassByAlias );
use DE_EPAGES::Core::API::Error qw(ExistsError GetError);
use DE_EPAGES::Core::API::Log qw (GetLog LogDebug);
use DE_EPAGES::WebInterface::API::MessageCenter qw( SynchronizeCache );
use DE_EPAGES::Core::API::PerlTools qw( GetCurrentDateTime );
use DE_EPAGES::Core::API::TestParameter qw( TestObject TestString TestInteger );
use DE_EPAGES::Presentation::API::PageCache qw (UpdatePageCache);
use DE_EPAGES::Object::API::Language qw (GetPKeyLanguageByCode);
use DE_EPAGES::Content::API::XML::StyleImportHandler qw( ImportStyle );
my ( $storename, $shop, $nooutput, $help );
GetOptions(
'storename=s' => \$storename,
'storename=s' => \$storename,
'nooutput!' => \$nooutput,
'shop=s' => \$shop,
'help!' => \$help
);
if ($help) {
Usage();
return 0;
}
RunScript( 'Sub' => \&Main );
sub DoIt {
my ($shop) = @_;
# my $Shop = LoadObjectByPath($path);
my @Shops;
my $ObjectShop;
# print $shop;
if (ExistsObjectByPath($shop) ) {
print "moro";
}
my $TheShop = LoadObjectByPath($shop);
print "Starting to import style to the shop: " . $shop . "\n";
# DE_EPAGES::Content::API::XML::StyleImportHandler::ImportStyle
my $ImportFile = '/srv/epages/eproot/Cartridges/vanilla.theme';
my ($aWarnings, undef) = ImportStyle($ImportFile, $TheShop, 2, 1);
# if ( defined($shop) && ExistsObjectByGUID($shop) ) {
# $TheShop = LoadObjectByGUID($shop);
# } else {
# print "Shop could not be found, exiting... \n";
# return;
# }
# my $ProductZoomWidth = $TheShop->get('ProductZoomWidth');
# print "Current value is: '$ProductZoomWidth'\n";
# my $trimmedValue = $ProductZoomWidth;
# $trimmedValue =~ s/\s//g; # remove spaces
# print "Trimmed value is: '$trimmedValue'. Setting it ->\n";
# $TheShop->set({'ProductZoomWidth' => $trimmedValue});
# my $valueAfter = $TheShop->get('ProductZoomWidth');
# print "Value after set: '$valueAfter'.\n";
# print "Done\n";
return;
}
sub Main {
if ( !defined $storename || $storename eq "" ) {
Usage("Missing required parameter -storename");
return 0;
}
if ( !defined $shop || $shop eq "" ) {
Usage("Missing required parameter -shop");
return 0;
}
if ( defined $storename ) {
# my $ref = \DoIt($shop);
eval { RunOnStore( Store => $storename, Sub => sub {
DoIt($shop);
})};
if ( ExistsError() ) {
my $Error = GetError();
print $Error->longMessage . "\n\n";
GetLog->debug( "Error:", $Error->message );
}
}
SynchronizeCache();
}
sub Usage {
my ($Message) = @_;
print STDERR "$Message\n\n" if defined $Message;
print <<END_USAGE;
Description:
Remove spaces from Shop attribute ProductZoomWidth.
Usage:
perl $0 options [flags]
Options:
-storename store name [required]
-shop shop guid [required]
-nooutput option to display messages in the terminal [optional]
Flags:
-help show the command line options
Example:
perl $0 -storename Store -shop 5865B197-AA75-55EA-3D01-0A28100AF4DB
END_USAGE
exit 2;
}
# sub ImportStyles {
# my $self = shift;
# my ($Servlet) = @_;
# my $Shop = $Servlet->object;
# my $Form = $Servlet->form;
# my $hValues = $Form->form($Shop, 'ImportStyle');
# my $PrivatePath = $Shop->get('PrivatePath');
# my $ImportFile = $PrivatePath . '/importStyle.zip';
# my (undef, $hResponseContent) = Upload($Shop, $Form, {'FormName' => 'StyleExportImport', 'Path' => $PrivatePath .'/', 'FileName' => 'importStyle', 'Extension' => 'zip', 'InputName' => 'ImportFile', 'Index' => 0});
# $Servlet->vars(
# 'ResponseContent', $hResponseContent
# );
# # Add warnings to Servlet.
# $Form->mapFormError({
# 'Form' => 'StyleExportImport',
# 'Name' => 'Export'
# }, $_) foreach @$aWarnings;
# $Servlet->vars('FormErrors', $Form->errors);
# return;
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment