Skip to content

Commit

Permalink
Several stock level request to avoid too long URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Aug 1, 2018
1 parent 0079755 commit 8d4e35d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
30 changes: 28 additions & 2 deletions client/html/src/Client/Html/Catalog/Base.php
Expand Up @@ -450,6 +450,7 @@ protected function getStockUrl( \Aimeos\MW\View\Iface $view, array $products )
* @see client/html/catalog/stock/url/controller
* @see client/html/catalog/stock/url/action
* @see client/html/catalog/stock/url/config
* @see client/html/catalog/stock/url/max-items
*/
$target = $view->config( 'client/html/catalog/stock/url/target' );

Expand All @@ -466,6 +467,7 @@ protected function getStockUrl( \Aimeos\MW\View\Iface $view, array $products )
* @see client/html/catalog/stock/url/target
* @see client/html/catalog/stock/url/action
* @see client/html/catalog/stock/url/config
* @see client/html/catalog/stock/url/max-items
*/
$cntl = $view->config( 'client/html/catalog/stock/url/controller', 'catalog' );

Expand All @@ -482,6 +484,7 @@ protected function getStockUrl( \Aimeos\MW\View\Iface $view, array $products )
* @see client/html/catalog/stock/url/target
* @see client/html/catalog/stock/url/controller
* @see client/html/catalog/stock/url/config
* @see client/html/catalog/stock/url/max-items
*/
$action = $view->config( 'client/html/catalog/stock/url/action', 'stock' );

Expand All @@ -504,10 +507,28 @@ protected function getStockUrl( \Aimeos\MW\View\Iface $view, array $products )
* @see client/html/catalog/stock/url/target
* @see client/html/catalog/stock/url/controller
* @see client/html/catalog/stock/url/action
* @see client/html/url/config
* @see client/html/catalog/stock/url/max-items
*/
$config = $view->config( 'client/html/catalog/stock/url/config', [] );

/** client/html/catalog/stock/url/max-items
* Maximum number of product stock levels per request
*
* To avoid URLs that exceed the maximum amount of characters (usually 8190),
* each request contains only up to the configured amount of product codes.
* If more product codes are available, several requests will be sent to the
* server.
*
* @param integer Maximum number of product codes per request
* @since 2018.10
* @category Developer
* @see client/html/catalog/stock/url/target
* @see client/html/catalog/stock/url/controller
* @see client/html/catalog/stock/url/action
* @see client/html/catalog/stock/url/config
*/
$max = $view->config( 'client/html/catalog/stock/url/config', 200 );


$codes = [];

Expand All @@ -516,8 +537,13 @@ protected function getStockUrl( \Aimeos\MW\View\Iface $view, array $products )
}

sort( $codes );
$urls = [];

while( ( $list = array_splice( $codes, -$max ) ) !== [] ) {
$urls[] = $view->url( $target, $cntl, $action, array( "s_prodcode" => $list ), [], $config );
}

return $view->url( $target, $cntl, $action, array( "s_prodcode" => $codes ), [], $config );
return array_reverse( $urls );
}


Expand Down
4 changes: 3 additions & 1 deletion client/html/templates/catalog/detail/header-standard.php
Expand Up @@ -57,7 +57,9 @@
<?php endif; ?>

<?php if( isset( $this->detailStockUrl ) ) : ?>
<script type="text/javascript" defer="defer" src="<?= $enc->attr( $this->detailStockUrl ); ?>"></script>
<?php foreach( (array) $this->detailStockUrl as $url ) : ?>
<script type="text/javascript" defer="defer" src="<?= $enc->attr( $url ); ?>"></script>
<?php endforeach ?>
<?php endif; ?>

<?= $this->get( 'detailHeader' ); ?>
Expand Up @@ -11,5 +11,7 @@

?>
<?php if( isset( $this->itemsStockUrl ) ) : ?>
<script type="text/javascript" defer="defer" src="<?= $enc->attr( $this->itemsStockUrl ); ?>"></script>
<?php foreach( (array) $this->promoStockUrl as $url ) : ?>
<script type="text/javascript" defer="defer" src="<?= $enc->attr( $url ); ?>"></script>
<?php endforeach ?>
<?php endif; ?>
6 changes: 4 additions & 2 deletions client/html/templates/catalog/lists/promo-header-standard.php
Expand Up @@ -11,5 +11,7 @@

?>
<?php if( isset( $this->promoStockUrl ) ) : ?>
<script type="text/javascript" defer="defer" src="<?= $enc->attr( $this->promoStockUrl ); ?>"></script>
<?php endif; ?>
<?php foreach( (array) $this->promoStockUrl as $url ) : ?>
<script type="text/javascript" defer="defer" src="<?= $enc->attr( $url ); ?>"></script>
<?php endforeach ?>
<?php endif ?>

0 comments on commit 8d4e35d

Please sign in to comment.