Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Error Handling #45

Closed
heldchen opened this issue Sep 6, 2016 · 1 comment
Closed

Add Error Handling #45

heldchen opened this issue Sep 6, 2016 · 1 comment

Comments

@heldchen
Copy link

heldchen commented Sep 6, 2016

during our site development in the last few weeks, there were several moments where there were exceptions thrown inside the boxalino intelligence plugin: bad configurations, unknown bx widget name, network problems, timeouts, webservice errors due to new attributes, webservice errors due to missing attribute values etc. in all these cases, the website was at best severely cripled or not working at all due to missing proper error handling.

the plugin should:

  • define a module operation mode ("production" <-> "development") in the configuration
  • if production mode is set to "production":
    • catch all exceptions and handle them gracefully
    • depending on the exception "gracefully" should mean:
      • fallback to the magento internal functionality (product recommendations, upsell, full text search)
      • or output a user friendly error message instead of the expected block content
      • or silently discard errors for non-vital elements

here's a quick example for the Crossell class:

/**
 * @param bool $execute
 * @return $this|array|null
 */
public function getItems($execute = true){

    if($this->bxHelperData->isCrosssellEnabled()){
        try {
            $config = $this->_scopeConfig->getValue('bxRecommendations/cart', $this->scopeStore);

            $products = array();
            foreach ($this->getQuote()->getAllItems() as $item) {
                $product = $item->getProduct();
                if ($product) {
                    $products[] = $product;
                }
            }

            $choiceId = (isset($config['widget']) && $config['widget'] != "") ? $config['widget'] : 'basket';
            $entity_ids = $this->p13nHelper->getRecommendation(
                $choiceId,
                'basket',
                $config['min'],
                $config['max'],
                $products,
                $execute
            );

            if(!$execute){
                return null;
            }

            if ((count($entity_ids) == 0)) {
                $entity_ids = array(0);
            }

            $items = $this->factory->create()
                ->addFieldToFilter('entity_id', $entity_ids)->addAttributeToSelect('*');
            $items->load();

            foreach ($items as $product) {
                $product->setDoNotUseCategoryId(true);
            }

            return $items;
        }
        catch (\Exception $ex)
        {
            // report
        }
    }
   return parent::getItems();
}
@heldchen
Copy link
Author

implemented in latest commits, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant