[TYPO3-commerce] using allArticles=0 and stock-handling

Morten Haggren mo at idefa.dk
Thu Sep 23 09:03:59 CEST 2010


Hi Sven,

It's understandable that the code lines have changes since those 
comments ( it's been 2 years after all ;) )

if you are getting crashes with the first article out of stock it seems 
that get selectattribute_matrix still haven't been fixed or your are 
having cache problems.

The way we "solved" it were to use an extension that xclasses to 
implement the version of get_selectattribute_matrix that is listed in 
that bug, and uses a hook to change enable fields to remove stockless 
articles

____________________________
Hook:
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_page.php']['addEnableColumns'][]

function:
     function enableFields($params,$caller){
         if ( TYPO3_MODE != 'FE' ) { return '' ; }
         if ( $params['table'] != 'tx_commerce_articles' ) { return ''; }
         if ( 
$GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_commerce_pi1.']['articles.']['showWithNoStock']==0 
){
         #    error_log('disabling showing stock!' );
             return ' AND tx_commerce_articles.tx_comdefaultstock_stock 
 > 0 ';
         }else{
          return '';
         }
     }
__________________________


ofcourse this means that rather than be grayed out options disappear 
completely from the drop downs. To make sure the drop downs combinations 
are always up to date we use ajax ( to avoid the anoying scroll to top / 
page reload that otherwise occures on long articles ) to replace the 
entire article subpart every time the user changes an attribute choices.

It works for us - but it's not really general purpose enough that it's 
something I'd feel comfortable releasing to the public as it is quite a 
long list of dirty hacks.


It's been a while since I stuck my head into that part of the commerce 
code but iirc the whole debacle comes from the code that generates the 
drop downs gets a list of articleIds and then just grabs the first one ( 
by reset() the array if memory serves ) and use that with out checking 
if it's in stock, how ever the article class refuses to load out of 
stock articles and so you end up with a stdObject that is then attempted 
to be used as an article object => crash.

Now that is all from memory but it should give you some idea of what to 
dig at ;)


/Morten Haggren

ps. if your interested I can try and see if I clean the extension we use 
enough that it can run outside our environment. It'd still be a hacky 
solution but..

On 2010-09-22 19:22, Sven Schumacher wrote:
> Hmmm,
>
> Am 22.09.2010 08:30, schrieb Morten Haggren:
>> Hi Sven,
>>
>> You've run into one of the oldest bugs plauging commerce ;)
>>
>>
>> http://forge.typo3.org/issues/1345
>>
>> I suggest you browse up on the issue, somewhere in there is the fix we
>> are running on our shops ( a hook into enableColumns ).
>
> line 1103 (which is mentioned in the comments) is a comment and in the
> bugtracker is not the original context mentioned, so finding that line
> was a little bit tricky, to add
>
> if (is_object($this->articles[$this->articles_uids[$j]]) &&
> ($this->articles[$this->articles_uids[$j]] instanceof tx_commerce_article))
>
> before that line. But 1169 contains already the above mentioned line, so
> I think in trunk this is already fixed - or should be there another
> line, where to add that line?
>
> With plugin.tx_commerce_pi1.articles.showWithNoStock=1 it still crashes,
> because the first attribute-combination is out of stock - like mentioned
> in the thread this wasn't fixed so far - how do you handle this bug?
> Perhaps there is an error in my extension for the hook you mentioned...
> (I've attached it to this message, so perhaps, you might be so kind and
> take a look on it?).
>
> For generating the select-fields (especially because of the
> disabled="disabled"-feature) there should be the chance to check at that
> place if the article combination is "in stock" and return "outOfStock"
> otherwise (instead of disabled for non existing article-combinations).
> So near line 902 of commerce/lib/class.tx_commerce_product.php:
>
> $selectMatrix[$kV][$key] = 'disabled';
>
> should be the right point to start otherwise, or do you think, that is
> the wrong way, to solve the problem?
>
> Thanks so far
>
> Sven
>
>


-- 
RewriteRule ^Morten Olesen$ Morten Haggren [R=301,L]


More information about the TYPO3-project-commerce mailing list