コード例 #1
0
 public function setProduct($product, $combination)
 {
     // create the product
     $context = Context::getContext();
     $this->give_it_product = new GiveItSdkProduct();
     $this->give_it_product->setCurrency($context->currency->iso_code);
     $usetax = Product::getTaxCalculationMethod((int) $context->customer->id) != PS_TAX_EXC;
     if ($combination['id_product_attribute'] == 0) {
         $combination['attributes'] = '';
         $image = Product::getCover($product->id);
     } else {
         $comb = new Combination($combination['id_product_attribute']);
         if ($image = $comb->getWsImages()) {
             $image = $image[0];
             $image['id_image'] = $image['id'];
         }
     }
     $image['id_product'] = $product->id;
     $image['id_image'] = Product::defineProductImage($image, Context::getContext()->language->id);
     $img_profile = version_compare(_PS_VERSION_, '1.5', '<') ? 'home' : ImageType::getFormatedName('medium');
     $image = $image ? $context->link->getImageLink($product->link_rewrite, $image['id_image'], $img_profile) : '';
     // first, set the product details.
     $this->give_it_product->setProductDetails(array('code' => $product->id . '_' . $combination['id_product_attribute'], 'price' => (int) (Product::getPriceStatic((int) $product->id, $usetax, $combination['id_product_attribute']) * 100), 'name' => $product->name . ($combination['attributes'] ? ' : ' . $combination['attributes'] : ''), 'image' => $image));
     $delivery = $this->setDelivery();
     // add the delivery option to the product
     $this->give_it_product->addBuyerOption($delivery);
     //We should validate this product
     $this->product_valid = $this->give_it_product->validate();
 }
コード例 #2
0
 protected function generateProductAttributesData()
 {
     $delimiter = ';';
     $line = array();
     $titles = array();
     $new_path = new Sampledatainstall();
     $f = fopen($new_path->sendPath() . 'output/product_attributes.vsc', 'w');
     foreach ($this->product_attribute_fields as $field => $array) {
         $titles[] = $array['label'];
     }
     fputcsv($f, $titles, $delimiter, '"');
     $product_attributes = $this->getAllProductsAttributes();
     if ($product_attributes) {
         foreach ($product_attributes as $product_attribute) {
             $pa = new Combination($product_attribute);
             foreach ($this->product_attribute_fields as $field => $array) {
                 $line[$field] = property_exists('Combination', $field) && !is_array($pa->{$field}) && !Tools::isEmpty($pa->{$field}) ? $pa->{$field} : '';
             }
             $value = $this->getAttributeValues($pa->id);
             $line['values'] = $value ? implode(',', $value) : '';
             $attr_images = array();
             $images = $pa->getWsImages();
             foreach ($images as $image) {
                 $attr_images[] = $image['id'];
             }
             $line['image'] = $attr_images ? implode(',', $attr_images) : '';
             if (!$line[$field]) {
                 $line[$field] = '';
             }
             fputcsv($f, $line, $delimiter, '"');
         }
     }
     fclose($f);
 }