rss search

next page next page close

AmazonComponent für CakePHP 1.2

Yeah.. OpenSource!

Ich habe durch Zufall noch eine alte Amazon Komponente gefunden die ich bisher nicht veröffentlich habe. Da ich mich ja auf GitHub niederlasse, habe ich die mal kurz überarbeitet und meinem cake-bits Repository hinzugefügt.

Link:
http://github.com/m3nt0r/cake-bits/tree/master/components/amazon.php

Gucken, und ...

PHP:
  1. // some controller ...
  2.     var $components = array('Amazon');
  3.  
  4.     function beforeFilter() {
  5.         $this->Amazon->setAccessKey( Configure::read('App.APIs.AmazonKey') );
  6.         $this->Amazon->setAssociateTag( Configure::read('App.APIs.AmazonTag') );
  7.     }
  8.     function index() {
  9.         $items = $this->Amazon->itemSearch('DVD', 'Title', 'Small,Offers');
  10.         if (!$items) {
  11.             pr ($this->Amazon->getLastErrors()); // pop some errors
  12.         } else {
  13.             $this->set('items', $items);
  14.         }
  15.     }
  16.     function view($asin) {
  17.         $item = $this->Amazon->itemLookup( $asin );
  18.         if (!$item) {
  19.             pr ($this->Amazon->getLastErrors()); // pop some errors
  20.         } else {
  21.             $this->set('item', $item);
  22.         }
  23.     }

Das wäre das eine... Das andere ist der remote shopping cart.

... kaufen!

PHP:
  1. // some other controller ...
  2.     function add() {
  3.         if ($this->data) {
  4.             $this->Amazon->cartThem(array(
  5.                 array(
  6.                     'quantity' => $this->data['Cart']['quantity'],
  7.                     'offerId' => $this->data['Cart']['offerId']
  8.                 ) // ... could be a larger collection. no prob.
  9.             ));
  10.             $this->redirect(aa('action', 'view'));
  11.         }
  12.     }
  13.     function edit() {
  14.         if ($this->data) {
  15.             $item_id = $this->data['Cart']['cartItemId'];
  16.             $quantity = $this->data['Cart']['quantity'];
  17.             $this->Amazon->cartUpdate($item_id, $quantity);
  18.             $this->redirect(aa('action', 'view'));
  19.         }
  20.     }
  21.     function view() {
  22.         $this->set('cart', $this->Amazon->cartGet());
  23.         $this->set('cartHasItems', $this->Amazon->cartHasItems());
  24.         $this->set('cartIsActive', $this->Amazon->cartIsActive());
  25.     }

Viel Spass damit!


AmazonComponent für CakePHP 1.2

Ich habe durch Zufall noch eine alte Amazon Komponente gefunden die ich bisher nicht veröffentlich habe. Anbei der Link und ein paar Beispiele.
article post