Friday, August 24, 2018

Override not working on prestashop 1.7 Category class

Why is prestashop don't save my modification into database? I've done an override on the Category.php (prestashop 1.7) class file, here is my code:

/override/classes/Category.php

class Category extends CategoryCore { /** * afficher/masquer les produits */ public $show_products = 1; public $andrana;

public function __construct($idCategory = null, $idLang = null, $idShop = null)
{
    $definition = self::$definition;

    $definition['fields']['show_products'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true);
    $definition['fields']['andrana'] = array(
        'type' => self::TYPE_HTML,
        'lang' => true,
        'validate' => 'isCleanHtml'
    );
    parent::__construct($idCategory, $idLang, $idShop);
}

}

/override\controllers\admin\AdminCategoriesController.php

class AdminCategoriesController extends AdminCategoriesControllerCore {

public function renderForm()
{
    $this->fields_form_override = array(
        array(
            'type' => 'switch',
            'label' => $this->trans('Afficher les produits', array(), 'Admin.Global'),
            'name' => 'show_products',
            'required' => false,
            'is_bool' => true,
            'values' => array(
                array(
                    'id' => 'active_on',
                    'value' => 1,
                    'label' => $this->trans('Enabled', array(), 'Admin.Global')
                ),
                array(
                    'id' => 'active_off',
                    'value' => 0,
                    'label' => $this->trans('Disabled', array(), 'Admin.Global')
                )
            )
        ),
        array(
            'type' => 'textarea',
            'label' => $this->trans('Andrana', array(), 'Admin.Global'),
            'name' => 'andrana',
            'autoload_rte' => true,
            'lang' => true,
            'hint' => $this->trans('Invalid characters:', array(), 'Admin.Notifications.Info').' <>;=#{}'
        ),
    );
    return parent::renderForm();
}

}

PS: I've added "show_products" on ps_category table and "andrana" in ps_category_lang table

Please help me :(

Solved

change the __construct to:

public function __construct($idCategory = null, $idLang = null, $idShop = null)
{

    self::$definition['fields']['show_products'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true);
    self::$definition['fields']['andrana'] = array(
        'type' => self::TYPE_HTML,
        'lang' => true,
        'validate' => 'isCleanHtml'
    );
    parent::__construct($idCategory, $idLang, $idShop);
}

Monday, August 20, 2018

Chrome 45 on Galaxy S6 not choosing right img based on srcSet attribute

Chrome 46 on my desktop loads the right images when i resize the browser to different widths. However on my phone it loads the largest image! the 1024w one. When i go to http://html5test.com/ on my phone it says its supported. Can anyone confirm that it's just not working correctly on mobile?


Solved

Your S6 has a device width of 360 pixels.

Its display has a super-high pixel density of 4x, so a total amount of 4 * 360 = 1440 physical pixels width in portrait orientation. (4 * 640 = 2560 in landscape)

80% of that, as specified in your sizes attribute, is 1152 physical pixels wide, so the your browser is correct in trying to get the largest image you have for that space on such a high-ppi screen.

I hope this helps!


Sunday, August 19, 2018

rCharts highlight charts in shiny not working

Using the answer to an existing question as a base for reproducible code here

I get the following error, and am unsure why it does not work...It seems to be a generic problem when rendering hPlot type charts in shiny, as I constantly keep getting the same error

Listening on http://127.0.0.1:7537
Error in normalizePath(directoryPath, mustWork = TRUE) : 
  path[1]="": No such file or directory


Error in normalizePath(directoryPath, mustWork = TRUE) : 
  path[1]="": No such file or directory
> traceback()
21: normalizePath(directoryPath, mustWork = TRUE)
20: addResourcePath(LIB$name, LIB$url)
19: singleton(addResourcePath(LIB$name, LIB$url))
18: withCallingHandlers(expr, message = function(c) invokeRestart("muffleMessage"))
17: suppressMessages(singleton(addResourcePath(LIB$name, LIB$url)))
16: showOutput("myChart", "Highcharts")
15: tag("div", list(...))
14: tags$div(...)
13: div(class = paste0("col-sm-", width), ...)
12: mainPanel(showOutput("myChart", "Highcharts"))
11: tag("div", list(...))
10: tags$div(...)
9: div(class = "row", sidebarPanel, mainPanel)
8: tag("div", list(...))
7: tags$div(...)
6: div(class = "container-fluid", div(class = "row", headerPanel), 
       div(class = "row", sidebarPanel, mainPanel))
5: tagList(if (!is.null(title)) tags$head(tags$title(title)), if (!is.null(theme)) {
  tags$head(tags$link(rel = "stylesheet", type = "text/css", 
                      href = theme))
}, list(...))
4: attachDependencies(tagList(if (!is.null(title)) tags$head(tags$title(title)), 
                              if (!is.null(theme)) {
                                tags$head(tags$link(rel = "stylesheet", type = "text/css", 
                                                    href = theme))
                              }, list(...)), importBootstrap())
3: bootstrapPage(div(class = "container-fluid", div(class = "row", 
                                                    headerPanel), div(class = "row", sidebarPanel, mainPanel)))
2: pageWithSidebar(headerPanel("rCharts: Highcharts"), sidebarPanel(selectInput(inputId = "x", 
                                                                                label = "Choose X", choices = c("SepalLength", "SepalWidth", 
                                                                                                                "PetalLength", "PetalWidth"), selected = "SepalLength")), 
                   mainPanel(showOutput("myChart", "Highcharts")))
1: runApp(list(ui = pageWithSidebar(headerPanel("rCharts: Highcharts"), 
                                    sidebarPanel(selectInput(inputId = "x", label = "Choose X", 
                                                             choices = c("SepalLength", "SepalWidth", "PetalLength", 
                                                                         "PetalWidth"), selected = "SepalLength")), mainPanel(showOutput("myChart", 
                                                                                                                                         "Highcharts"))), server = function(input, output) {
                                                                                                                                           output$myChart <- renderChart2({
                                                                                                                                             h1 <- Highcharts$new()
                                                                                                                                             h1$chart(type = "spline")
                                                                                                                                             h1$series(data = c(1, 3, 2, 4, 5), dashStyle = "longdash")
                                                                                                                                             h1$series(data = c(NA, 4, 1, 3, 4), dashStyle = "shortdot")
                                                                                                                                             h1$legend(symbolWidth = 80)
                                                                                                                                             return(h1)
                                                                                                                                           })
                                                                                                                                         }))

below is my sessionInfo after an upgrade in rCharts...which resulted in the same error...also note that highlight charts work locally when viewing in RStudio's viewer, but not in shiny when using the showOutput function

> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: powerpc64le-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_0.11.1  rCharts_0.4.5

loaded via a namespace (and not attached):
 [1] codetools_0.2-8 digest_0.6.8    grid_3.1.1      htmltools_0.2.6
 [5] httpuv_1.3.2    lattice_0.20-29 mime_0.3        nabor_0.4.4    
 [9] plyr_1.8.1      R6_2.0.1        Rcpp_0.11.5     RJSONIO_1.3-0  
[13] tools_3.1.1     whisker_0.3-2   xtable_1.7-4    yaml_2.1.13   

Solved

Changing "Highcharts" to "highcharts" inside showOutput() fixes it for me (using rCharts version 0.4.5):

require(rCharts)
require(shiny)
runApp(list(
  ui =  pageWithSidebar(
    headerPanel("rCharts: Highcharts"),
    sidebarPanel(selectInput(
      inputId = "x",
      label = "Choose X",
      choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'),
      selected = "SepalLength"
    )),
    mainPanel(showOutput("myChart", "highcharts"))
  ),
  server = function(input, output){
    output$myChart <- renderChart2({
      h1 <- Highcharts$new()
      h1$chart(type = "spline")
      h1$series(data = c(1, 3, 2, 4, 5), dashStyle = "longdash")
      h1$series(data = c(NA, 4, 1, 3, 4), dashStyle = "shortdot")
      h1$legend(symbolWidth = 80)
      return(h1)
    })
  }
))

Saturday, August 18, 2018

Compiler Understanding - assign in a if statement

I recently came across this syntax

int i;
String s = "test";
if(!((i=s.length()) == 0)) {
    System.out.println(i);
}

If you are wondering what it prints it prints:

4

Now I know this code compiles as well as runs correctly. I also understand that this puts the value of s.length into i. I want to know how is this possible ? How can we equate/assign a variable in an if clause. Does some one have any insight not how this work with the compiler

Solved

An assignment expression

i=s.length()

resolves to the value being assigned.

From the JLS

At run time, the result of the assignment expression is the value of the variable after the assignment has occurred. The result of an assignment expression is not itself a variable.

I don't want to go get the byte code right now, but basically

  1. the value of of s is pushed on the stack
  2. that value is popped and dereferenced to invoke String#length()
  3. the result is pushed on the stack
  4. the same result is pushed on the stack again
  5. that value is popped from the stack and stored in i
  6. the value of 0 (possibly not as there might be a byte code instruction for comparison with 0) is pushed on the stack
  7. the value and 0 are both popped from the stack and compared, with a jump instruction depending on the result

To understand this, let's try to dissect it, statement per statement

if(!((i=s.length()) == 0))
s.length() //results to 4;
i=s.length() //assigned i=4
i=s.length() == 0 //false
!i=s.length() == 0 //invert, becomes true
if(true) {
    //prints i
}

The result of a Java assignment is the value assigned, that means this

(!((i=s.length()) == 0)) 

Assigns s.length() to i, and then checks that that value (s.length()) is NOT 0.


The assignment operator is a ordinary expression.

Like any other expression, you can put it wherever you want to.

The value of this expression is the value being assigned. (This is also why you can write a = b = c)


Java compiler operates on sort of a stack parser where it evaluates from left to right each line. Whenever it encounters a right parenthesis the previous statement back to the last left parenthesis will be executed before anything else so...

The inner-most parenthesis will be evaluated before anything else which is of course (i=s.length()).

I'm not at my main computer right now so I can't really test this but I'm sure you'd receive a syntax error if you remove the parentheses around i=s.length().