Jump to content

Got new issue on creating an product in 1.7


Recommended Posts

Hi. 

We just moved to 1.7 and suddenly our plugin creates an weird error: vartiants dont work on the default theme.

 

The Situation: 

We create products and Variants with our custom code like we always did. No errors so far. But if i try to change the variant on an just created product it keeps me stuck on the default variant. Clicking is not changing it. Manual URL re-writing is not changing it. 

 

If I use the same code to just add an variant to an manually created product it just works fine. So my conclusion is, that the problem is on creating the "base"-product itself.

 

So far i was not able to find out what on earth is causing this error.

 

- The "product-variants.tpl" just gets the same valid data. absolute no difference.

- Any db table containing "product" ist perfectly the same and sync.

- and YES the cache is inactive . . . .

 

My currently last shot is to post the code here, hopefully someone "notices" something that might be bothersome on 1.7.

Im thankfull for any suggestion or comment.

<?php 

// ...

$categoryId = intval($this->getCategoryId($categoryName));
$product = new Product();
$product->ean13 = $ean13;
$product->upc = $upc;
$product->reference = $afterBuyID;
$product->name = array((int)Configuration::get('PS_LANG_DEFAULT') =>  $name);

$product->id_manufacturer = $this->getManufacturerId($manufacturer);
if(!$product->id_manufacturer || $product->id_manufacturer==0) {
    print "Manufacturer Could not be set!";
}

$product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') =>  $link_rewrite);
$product->id_category = $categoryId;
$product->id_category_default = 2; // Start Category
$product->redirect_type = '404';
$product->price = $price;
$product->id_tax_rules_group = 0;
$product->description = $description;
$product->minimal_quantity = 1;
$product->show_price = 1;
$product->on_sale = 0;
$product->online_only = 0;
$product->is_virtual=0; // is not virtual!!! Else no variants!
if($product->save()) {

    StockAvailable::setQuantity($product->id,0, $quantity); // 0 because attribute "optional" from Prestashop source-code comment
    print $product->id;
    if(!$product->addToCategories(array($categoryId))) {
        print "Adding Category Failed!";
    }
// ...

?>
Link to comment
Share on other sites

  • 3 weeks later...

Okay Update.

After spending a whole sunny day on this issue i tracked some things down. 

 

First: The exact place when it seems to happend is on themes\core.js around line 2522

_jquery2['default'].post(event.reason.productUrl, { ajax: '1', action: 'refresh' }, null, 'json').then(function (resp) {
     (0, _jquery2['default'])('.product-prices').replaceWith(resp.product_prices);

This call missleads to a wrong result. 

The previous call done at the ".product-refresh" on-click event returns the right variation. Bis this one stays sticky on that variation that is marked as default.

 

On the Backend side, on ProductController::displayAjaxRefresh i can see, that the "problem" occures right in the beginning. GetTemplateVarProduct calls getIdProductAttribute calls Tools::getValue ... and so on and so on. 

 

I wonder: what could cause this mess? Still nobody here with a clue? I mean. WTF? 
Is _jequery2['default'] hiding something?

 

Edit:

Fun fact: JS calls "http://presta.test.primopet.de/de/startseite/813-331-lllllll-1234567891011.html" .... 

but php's getallheaders() told me, he got called "http://presta.test.primopet.de/de/startseite/813-330-lllllll-1234567891011.html" ...

 

WTF? Chrome Debugger also says that we request 331 (the right one) ... Is there some kind of weird re-routing happening?

 

i2ulXwC.png

 

 

Edit over 5000: 

Im SO done with it. Same debug on an request that works:
I Request: /de/startseite/815-333-drfhfjgfhj.html?quantity_wanted=1#/68-farbe-tausendschonchen/69-groesse-l

ProductController gets: /de/startseite/815-332-drfhfjgfhj.html?quantity_wanted=1

Tools::getValue('id_product_attribute') returns: 333

 

Im so done with it. What-the-hell?

Edited by tharo (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

Found the Reason for this Bug. Prestashop 1.7 seems to fiddle as soon as an main product contains an EAN, but also has sub-variants aka attributes.

 

CartController.php->canonicalRedirection then trys to compare product+ean with product - whitch will always fail, and returns back to the default variant.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...