Services_Ebay
[ class tree: Services_Ebay ] [ index: Services_Ebay ] [ all elements ]

Source for file Item.php

Documentation is available at Item.php

  1. <?PHP
  2. /**
  3.  * Model for an eBay item
  4.  *
  5.  * $Id$
  6.  *
  7.  * @package Services_Ebay
  8.  * @author  Stephan Schmidt <schst@php.net>
  9.  */
  10. {
  11.    /**
  12.     * model type
  13.     *
  14.     * @var  string 
  15.     */
  16.     protected $type = 'Item';
  17.  
  18.    /**
  19.     * property that stores the unique identifier (=pk) of the model
  20.     *
  21.     * @var string 
  22.     */
  23.     protected $primaryKey = 'ItemID';
  24.  
  25.     /**
  26.     * create new item
  27.     *
  28.     * @param    array   properties
  29.     */
  30.     public function __construct($props$session = null)
  31.     {
  32.         if (is_array($props&& isset($props['Seller'])) {
  33.             $props['Seller'Services_Ebay::loadModel('User'$props['Seller']$session);
  34.         }
  35.         parent::__construct($props$session);
  36.     }
  37.  
  38.     public function __set($prop$value)
  39.     {
  40.         $this->properties['Item'][$prop$value;
  41.     }
  42.  
  43.    /**
  44.     * set the locations you will ship the item to
  45.     *
  46.     * @param    array 
  47.     */
  48.     public function setShipToLocations($ShipToLocations)
  49.     {
  50.         $this->properties['ShipToLocations'= array(
  51.                                                       'ShipToLocation' => $ShipToLocations
  52.                                                     );
  53.         return true;
  54.     }
  55.  
  56.    /**
  57.     * add a shipping service option
  58.     *
  59.     * @param    integer     shipping service, {@link http://developer.ebay.com/DevZone/docs/API_Doc/Appendixes/AppendixN.htm#shippingservices}
  60.     * @param    integer     priority (1-3)
  61.     * @param    float       cost for the item
  62.     * @param    float       cost for an additional item
  63.     * @return   boolean 
  64.     */
  65.     public function addShippingServiceOption($ShippingService$ShippingServicePriority$ShippingServiceCost$ShippingServiceAdditionalCost)
  66.     {
  67.         $option = array(
  68.                         'ShippingService'               => $ShippingService,
  69.                         'ShippingServicePriority'       => $ShippingServicePriority,
  70.                         'ShippingServiceCost'           => $ShippingServiceCost,
  71.                         'ShippingServiceAdditionalCost' => $ShippingServiceAdditionalCost,
  72.                     );
  73.         if (!isset($this->properties['ShippingServiceOptions'])) {
  74.             $this->properties['ShippingServiceOptions'= array(
  75.                                                                   'ShippingServiceOption' => array()
  76.                                                                );
  77.         }
  78.         array_push($this->properties['ShippingServiceOptions']['ShippingServiceOption']$option);
  79.         return true;
  80.     }
  81.     
  82.    /**
  83.     * add an international shipping service option
  84.     *
  85.     * @param    integer     shipping service, {@link http://developer.ebay.com/DevZone/docs/API_Doc/Appendixes/AppendixN.htm#shippingservices}
  86.     * @param    integer     priority (1-3)
  87.     * @param    float       cost for the item
  88.     * @param    float       cost for an additional item
  89.     * @param    array       locations for this shipping service options
  90.     * @return   boolean 
  91.     */
  92.     public function addInternationalShippingServiceOption($ShippingService$ShippingServicePriority$ShippingServiceCost$ShippingServiceAdditionalCost$ShipToLocations)
  93.     {
  94.         $option = array(
  95.                         'ShippingService'               => $ShippingService,
  96.                         'ShippingServicePriority'       => $ShippingServicePriority,
  97.                         'ShippingServiceCost'           => $ShippingServiceCost,
  98.                         'ShippingServiceAdditionalCost' => $ShippingServiceAdditionalCost,
  99.                         'ShipToLocations'               => array(
  100.                                                                 'ShipToLocation' => $ShipToLocations
  101.                                                                 )
  102.                     );
  103.         if (!isset($this->properties['InternationalShippingServiceOptions'])) {
  104.             $this->properties['InternationalShippingServiceOptions'= array(
  105.                                                                   'ShippingServiceOption' => array()
  106.                                                                );
  107.         }
  108.         array_push($this->properties['InternationalShippingServiceOptions']['ShippingServiceOption']$option);
  109.         return true;
  110.     }
  111.  
  112.    /**
  113.     * create a string representation of the item
  114.     *
  115.     * @return   string 
  116.     */
  117.     public function __toString()
  118.     {
  119.         if (isset($this->properties['Title'])) {
  120.             return $this->properties['Title'' (# '.$this->properties['ItemID'].')';
  121.         }
  122.         return '# '.$this->properties['ItemID'];
  123.     }
  124.  
  125.    /**
  126.     * get the item from eBay
  127.     *
  128.     * Use this to query by a previously set itemId.
  129.     *
  130.     * <code>
  131.     * $item = Services_Ebay::loadModel('Item', null, $session);
  132.     * $item->Id = 4501296414;
  133.     * $item->Get();
  134.     * </code>
  135.     *
  136.     * @param    int     DetailLevel
  137.     * @param    int     DescFormat
  138.     * @see      Services_Ebay_Call_GetItem
  139.     */
  140.     public function Get($DetailLevel = null$DescFormat = 0)
  141.     {
  142.         $args = array(
  143.                         'ItemID'        => $this->properties['Item']['Id'],
  144.                         'DescFormat'    => $DescFormat
  145.                     );
  146.         if (!is_null($DetailLevel)) {
  147.             $args['DetailLevel'$DetailLevel;
  148.         }
  149.  
  150.         $call Services_Ebay::loadAPICall('GetItem');
  151.         $call->setArgs($args);
  152.         
  153.         $tmp $call->call($this->session);
  154.         $this->properties = $tmp->toArray();
  155.         $this->eBayProperties = $this->properties;
  156.         unset($tmp);
  157.         return true;
  158.     }
  159.  
  160.    /**
  161.     * get cross promotions
  162.     *
  163.     * @param    int     DetailLevel
  164.     * @param    int     DescFormat
  165.     * @see      Services_Ebay_Call_GetCrossPromotions
  166.     */
  167.     public function GetCrossPromotions($PromotionMethod 'CrossSell'$PromotionViewMode = null)
  168.     {
  169.         $args = array(
  170.                         'ItemID'          => $this->properties['ItemID'],
  171.                         'PromotionMethod' => $PromotionMethod
  172.                     );
  173.         if (!is_null($PromotionViewMode)) {
  174.             $args['PromotionViewMode'$PromotionViewMode;
  175.         }
  176.  
  177.         $call Services_Ebay::loadAPICall('GetCrossPromotions');
  178.         $call->setArgs($args);
  179.         
  180.         return $call->call($this->session);
  181.     }
  182.     
  183.    /**
  184.     * add text to the item description
  185.     *
  186.     * @param    string 
  187.     * @return   boolean 
  188.     * @see      Services_Ebay_Call_AddToItemDescription
  189.     */
  190.     public function AddToDescription($Description)
  191.     {
  192.         $args = array(
  193.                         'ItemID'          => $this->properties['ItemID'],
  194.                         'Description'     => $Description
  195.                     );
  196.         $call Services_Ebay::loadAPICall('AddToItemDescription');
  197.         $call->setArgs($args);
  198.         
  199.         return $call->call($this->session);
  200.     }
  201.  
  202.    /**
  203.     * and an auction
  204.     *
  205.     * @param    integer 
  206.     * @return   array 
  207.     * @see      Services_Ebay_Call_EndItem
  208.     */
  209.     public function End($EndCode)
  210.     {
  211.         $args = array(
  212.                         'ItemID'  => $this->properties['ItemID'],
  213.                         'EndCode' => $EndCode
  214.                     );
  215.         $call Services_Ebay::loadAPICall('EndItem');
  216.         $call->setArgs($args);
  217.         
  218.         return $call->call($this->session);
  219.     }
  220.  
  221.    /**
  222.     * Add the item to eBay
  223.     *
  224.     * This starts a new auction
  225.     *
  226.     * @see      Services_Ebay_Call_RelistItem
  227.     */
  228.     public function Add()
  229.     {
  230.         if (isset($this->properties['ItemID']&& !is_null($this->properties['ItemID'])) {
  231.             throw new Services_Ebay_Exception('This item already has an ItemId and thus cannot be added.');
  232.         }
  233.         $call Services_Ebay::loadAPICall('AddItem'array($this));
  234.         
  235.         return $call->call($this->session);
  236.     }
  237.  
  238.    /**
  239.     * Re-list the item
  240.     *
  241.     * This adds a new auction with exactly the same item data
  242.     *
  243.     * @todo     check return value
  244.     * @see      Services_Ebay_Call_RelistItem
  245.     */
  246.     public function Relist()
  247.     {
  248.         $args = array(
  249.                         'ItemID'  => $this->properties['ItemID']
  250.                     );
  251.         $call Services_Ebay::loadAPICall('RelistItem');
  252.         $call->setArgs($args);
  253.         
  254.         return $call->call($this->session);
  255.     }
  256.  
  257.    /**
  258.     * Revise the item
  259.     *
  260.     * @return   boolean 
  261.     * @see      Services_Ebay_Call_ReviseItem
  262.     */
  263.     public function Revise()
  264.     {
  265.         $call Services_Ebay::loadAPICall('ReviseItem'array($this));
  266.         return $call->call($this->session);
  267.     }
  268.  
  269.    /**
  270.     * Add a second chance offer
  271.     *
  272.     * This adds a new auction with exactly the same item data
  273.     *
  274.     * @return   object Services_Ebay_Model_Item 
  275.     * @see      Services_Ebay_Call_AddSecondChanceItem
  276.     */
  277.     public function AddSecondChance($RecipientBidderUserId$Duration 'Days_3'$BuyItNowPrice = null)
  278.     {
  279.         $args = array(
  280.                         'OriginalItemID'        => $this->properties['ItemID'],
  281.                         'RecipientBidderUserID' => $RecipientBidderUserId,
  282.                         'Duration'              => $Duration,
  283.                     );
  284.         if ($BuyItNowPrice !== null{
  285.             $args['BuyItNowPrice'$BuyItNowPrice;
  286.         }
  287.         $call Services_Ebay::loadAPICall('AddSecondChanceItem');
  288.         $call->setArgs($args);
  289.         
  290.         return $call->call($this->session);
  291.     }
  292. }
  293. ?>

Documentation generated on Mon, 11 Mar 2019 15:49:48 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.