public function __construct($Item, $quantity = 1) { if (!is_object($Item)) { return; } // just a clone of another ShippingPackageItem if (is_a($Item, 'ShippingPackageItem')) { foreach (get_object_vars($Item) as $key => $value) { $this->{$key} = $value; } $this->quantity = $quantity; return; // no more information needed } // Reduced Copy from base item foreach (get_object_vars($Item) as $key => $value) { if (!in_array($key, array_keys(get_object_vars($this)))) { continue; } $this->{$key} = $value; } $this->fingerprint = 0; $this->quantity = $quantity; // Parent Item, need to gather information needed for packager if (is_a($Item, 'Item')) { $this->fingerprint = $Item->fingerprint(); // store reference index to cart contents foreach (shopp_cart_items() as $index => $CartItem) { if ($this->fingerprint == $CartItem->fingerprint()) { $this->index = $index; break; } } } }
/** * Determine the item subject data and match against it. * * @param ShoppCartItem $Item The Item to match against * @return boolean True if match, false for no match **/ private function items(ShoppCartItem $Item = null) { // Are we matching against a specific, individual item? if (null !== $Item) { return $this->item($Item); } // Do we have items in the cart? $items = shopp_cart_items(); if (empty($items)) { return false; } // If we do, let's see if any of them yield a match foreach ($items as $Item) { if (true === $this->item($Item)) { return true; } } return false; }